Answers for "from threading import thread"

5

create new thread python

from threading import Thread
from time import sleep

def threaded_function(arg):
    for i in range(arg):
        print("running")
        sleep(1)


if __name__ == "__main__":
    thread = Thread(target = threaded_function, args = (10, ))
    thread.start()
    thread.join()
    print("thread finished...exiting")
Posted by: Guest on June-27-2020
0

import thread

import thread

def eating():
  print('eating...')
  time.sleep(1)

def sleeping():
  print('sleeping...)
  time.sleep(5)
        
t1 = threading.Thread(target=eating)
t2 = threading.Thread(target=sleeping)

t1.start()
t2.start()
Posted by: Guest on October-11-2021

Code answers related to "from threading import thread"

Python Answers by Framework

Browse Popular Code Answers by Language