fork download
  1. import logging
  2. import threading
  3. import time
  4.  
  5. def thread_function(name):
  6. logging.info("Thread %s: starting", name)
  7. time.sleep(2)
  8. logging.info("Thread %s: finishing", name)
  9.  
  10. if __name__ == "__main__":
  11. format = "%(asctime)s: %(message)s"
  12. logging.basicConfig(format=format, level=logging.INFO,
  13. datefmt="%H:%M:%S")
  14.  
  15. logging.info("Main : before creating thread")
  16. x = threading.Thread(target=thread_function, args=(1,))
  17. logging.info("Main : before running thread")
  18. x.start()
  19. logging.info("Main : wait for the thread to finish")
  20. # x.join()
  21. logging.info("Main : all done")
Success #stdin #stdout #stderr 0.05s 10872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
20:20:24: Main    : before creating thread
20:20:24: Main    : before running thread
20:20:24: Thread 1: starting
20:20:24: Main    : wait for the thread to finish
20:20:24: Main    : all done
20:20:26: Thread 1: finishing