Python Multithreading How to create a Thread

Publié le: 12 janvier 2018
sur la chaîne: OSPY
1,073
10

Python Multithreading How to create a Thread and Run it

import threading
import time
import random

def myfunction(n):
rand_num = random.choice([30,50,40,2])
time.sleep(rand_num)
print "Executing myfunction in thread: ", n

for x in range(1,6):
t = threading.Thread(target=myfunction, args=(x,))
t.start()

Threading is a facility to allow multiple tasks to run
concurrently within a single process. Threads are independent,
concurrent execution through a program, and each thread has
Tits own stack.

Threads are usually contained in processes.
More than one thread can exist within the same process.
These threads share the memory and the state of the process.
In other words: They share the code or instructions and
the values of its variables.

Every process has at least one thread, i.e. the process
itself. A process can start multiple threads.

Threads of a process can share the memory of global variables.
If a global variable is changed in one thread, this change
is valid for all threads. A thread can have local variables.

Threads run in the same memory space, while processes
have separate memory.

How to View the thread:


Sur cette page du site, vous pouvez voir la vidéo en ligne Python Multithreading How to create a Thread durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur OSPY 12 janvier 2018, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,073 fois et il a aimé 10 téléspectateurs. Bon visionnage!