Answers for "run 2 def python"

1

run 2 def python

from threading import Thread
from time import sleep
# use Thread to run def in background
# Example:
def func1():
    while True:
        sleep(1)
        print("Working")

def func2():
    while True:
        sleep(2)
        print("Working2")

if __name__ == '__main__':
    Thread(target = func1).start()
    Thread(target = func2).start()
Posted by: Guest on March-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language