Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

run code at the same time 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

python run code at the same time

def a():
    print("Function a is running at time: " + str(int(time.time())) + " seconds.")

def b():
    print("Function b is running at time: " + str(int(time.time())) + " seconds.")

threading.Thread(target=a).start()
OUTPUT
Function a is running at time: 1585338789 seconds.
threading.Thread(target=b).start()
OUTPUT
Function b is running at time: 1585338789 seconds.
Comment

PREVIOUS NEXT
Code Example
Python :: print string elements in list python 
Python :: create dictionary 
Python :: unsupervised learning 
Python :: python append list 
Python :: make a label using tkinter in python 
Python :: get median using python 
Python :: docker flask 
Python :: rolling window pandas 
Python :: python plot label value 
Python :: python get 1st arg 
Python :: plot multiindex columns pandas 
Python :: flask set cookie 
Python :: transpose matrix in python without numpy 
Python :: python dict sortieren 
Python :: python single line if 
Python :: selenium python find element by class name with space 
Python :: pandas loc for list 
Python :: pytorch mse mae 
Python :: how to encode emoji to text in python 
Python :: basic flask app 
Python :: python check array exists 
Python :: train dev test split sklearn 
Python :: python counter nested dictionary 
Python :: make a new environment conda 
Python :: hugging face change directory model 
Python :: python sum lists element wise 
Python :: lemmatization 
Python :: python check if input() gives error 
Python :: python convert string to list of dictionaries 
Python :: how to set the value of a variable null in python 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =