Python Threading

threading.thread.start() or thread.start_new_thread()?



Posted by JB Uy on November 28, 2013 at 03:13 PM UTC
Edited on December 13, 2013 at 08:41 PM UTC
2 Notes

Passing arguments into the function for start():

from threading import Thread

my_thread = Thread(target=main_func, args=args, kwargs=kwargs)
my_thread.start()

What about:

my_thread.setDaemon(True)

threads are by default non-daemonic.

So the parent will wait until all it's children are done before exiting.

By setting Daemon to True, the parent will exit regardless of it's children being done.

Posted by JB Uy on November 28, 2013 at 03:21 PM UTC
Edited on November 28, 2013 at 03:39 PM UTC
via hutility.notedock.com | Link
thread.start_new_thread()

is lower level than

threading.Thread.start()

which provides an abstraction on top of the former.

Posted by JB Uy on November 28, 2013 at 03:16 PM UTC
Edited on November 28, 2013 at 03:21 PM UTC
via hutility.notedock.com | Link
Public Comments
comments powered by Disqus