Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to run function on different thread python

from threading import Thread
import time

def parallelFunc():
    for i in range(100):
      print("1")
      time.sleep(0.2)
      
def parallelFunc2():
    for i in range(100):
      print("2")
      time.sleep(0.2)
      
th = Thread(target=parallelFunc)
th2 = Thread(target=parallelFunc2)

th.start()
th2.start()

#Run code in parallel with other 2 functions

th.join()
th2.join()

#2 functions will loop at the same time
Comment

PREVIOUS NEXT
Code Example
Python :: intersection in list 
Python :: plt change legend coordinates 
Python :: os file exists 
Python :: python for loop with array 
Python :: python-binance 
Python :: mongodb check if substring in string 
Python :: email authentication python 
Python :: how to make a never ending loop in python 
Python :: python create and show screenshot 
Python :: NameError: name ‘pd’ is not defined 
Python :: python pandas cumulative return 
Python :: image in tkinter 
Python :: reduce in python 
Python :: convert base64 to image python 
Python :: python get name of tkinter frame 
Python :: python webdriver element not interactable 
Python :: feet to meter python 
Python :: python sort list in reverse 
Python :: python exceute 60 records per minute counter 
Python :: fiel to base64 python 
Python :: how to use enumerate instead of range and len 
Python :: how to install python libraries 
Python :: from PyQt5 import Qsci 
Python :: python async threading 
Python :: scipy correlation 
Python :: index of sorted list python 
Python :: perfect number program in python 
Python :: how to know where python is installed on windows 
Python :: how to roll longitude axis 
Python :: delete rows in dataframe pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =