Python Multithreading How to create a Thread

Publicado el: 12 enero 2018
en el canal de: 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:


En esta página del sitio puede ver el video en línea Python Multithreading How to create a Thread de Duración hora minuto segunda en buena calidad , que subió el usuario OSPY 12 enero 2018, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,073 veces y le gustó 10 a los espectadores. Disfruta viendo!