Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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()
Comment

Python multithreading

import threading 
  
def print_hello_three_times():
  for i in range(3):
    print("Hello")
  
def print_hi_three_times(): 
    for i in range(3): 
      print("Hi") 

t1 = threading.Thread(target=print_hello_three_times)  
t2 = threading.Thread(target=print_hi_three_times)  

t1.start()
t2.start()
Comment

PREVIOUS NEXT
Code Example
Python :: multiple functions tkinter 
Python :: rename column pandas 
Python :: multiple inputs in python 
Python :: renaming multiple columns in pandas 
Python :: password manager python 
Python :: django connection cursor 
Python :: replace nat with date pandas 
Python :: pandas new column from others 
Python :: python match phone number 
Python :: change default option optionmenu tkinter 
Python :: add pip to path 
Python :: python procedured 
Python :: python script header 
Python :: lista to txt python 
Python :: python set negative infinity 
Python :: reset django database 
Python :: python list comprehension with if 
Python :: ip regex python 
Python :: convert string to class name python 
Python :: how to get only certain columns in pandas 
Python :: create text file in directory python linux 
Python :: select specific rows from dataframe in python 
Python :: runtime.txt heroku python 
Python :: Installing packages from requirements.txt file 
Python :: how to draw a rectangle in pygame 
Python :: python regex get all matches 
Python :: python get volume free space 
Python :: for loop in django 
Python :: drop column with nan values 
Python :: video streaming flask 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =