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 :: python string exclude non alphabetical characters 
Python :: pandas drop rows with empty list 
Python :: boston dataset sklearn 
Python :: start new app in django 
Python :: create pdf from images python 
Python :: python class tostring 
Python :: python set current working directory to script location python 
Python :: is there a python command that clears the output 
Python :: fstring number format python 
Python :: how to code in python 
Python :: check dictionary is empty or not in python 
Python :: count number of occurrences of all elements in list python 
Python :: md5 hash python 
Python :: how to split image dataset into training and test set keras 
Python :: json load python 
Python :: remove duplicates based on two columns in dataframe 
Python :: check pip installed packages inside virtualenv 
Python :: update python in miniconda 
Python :: python datetime subtract seconds 
Python :: python delete header row 
Python :: pygame window 
Python :: convert birth date to age pandas 
Python :: make a specific column a df index 
Python :: plot python x axis range 
Python :: researchpy correlation 
Python :: python timedelta 
Python :: python filter a dictionary 
Python :: location of python in cmd 
Python :: how to roll longitude coordinate 
Python :: python image to video 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =