python - Migrating from thread to threading -


in python 2, used module thread create new threads, doing:

thread.start_new_thread(function_name, (arguments_tuple,))  

i know can run same code in python 3, except have replace import thread statement import _thread. explained in python docs:

this module provides low-level primitives working multiple threads (also called light-weight processes or tasks) — multiple threads of control sharing global data space. synchronization, simple locks (also called mutexes or binary semaphores) provided. the threading module provides easier use , higher-level threading api built on top of module.

how migrate piece of code new module syntax?

the new module destinated oop, example threading be:

import time threading import thread  def sleeper(i):     print "thread %d sleeps 5 seconds" %     time.sleep(5)     print "thread %d woke up" %  in range(10):     t = thread(target=sleeper, args=(i,))     t.start() 

changing import thread from threading import thread, , start_new_thread(func, (args,) thread(target=func, args=(args,).start() trick.


Comments