Python Multithreading How to create a Thread

Veröffentlicht am: 12 Januar 2018
auf dem Kanal: 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:


Auf dieser Seite können Sie das Online-Video Python Multithreading How to create a Thread mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer OSPY 12 Januar 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,073 Mal angesehen und es wurde von 10 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!