Horje
python multithreading tutorials Code Example
python multithreading tutorials
# Python program to illustrate the concept
# of threading
import threading
import os
  
def task1():
    print("Task 1 assigned to thread: {}".format(threading.current_thread().name))
    print("ID of process running task 1: {}".format(os.getpid()))
  
def task2():
    print("Task 2 assigned to thread: {}".format(threading.current_thread().name))
    print("ID of process running task 2: {}".format(os.getpid()))
  
if __name__ == "__main__":
  
    # print ID of current process
    print("ID of process running main program: {}".format(os.getpid()))
  
    # print name of main thread
    print("Main thread name: {}".format(threading.current_thread().name))
  
    # creating threads
    t1 = threading.Thread(target=task1, name='t1')
    t2 = threading.Thread(target=task2, name='t2')  
  
    # starting threads
    t1.start()
    t2.start()
  
    # wait until all threads finish
    t1.join()
    t2.join()




Python

Related
python -m pip install --upgrade pip /usr/bin/python: No module named pip Code Example python -m pip install --upgrade pip /usr/bin/python: No module named pip Code Example
example of python application  from github to docker image Code Example example of python application from github to docker image Code Example
giving number of letter in python Code Example giving number of letter in python Code Example
python string: escaping characters Code Example python string: escaping characters Code Example
python how to count ever yfile in fodler Code Example python how to count ever yfile in fodler Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8