
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.58 KB | hits: 8 | expires: Never
About threads and callbacks
import threading
def cb_func(data):
"""The callback function"""
print data
def th_func(callback):
"""The threaded function"""
# do some work here
callback('somedata')
thr = threading.Thread(target=th_func, args=(cb_func,)).start()
import threading
def cb_func():
"The callback function."
print 'Callback, in thread %s' % threading.current_thread().name
def th_func(callback):
"The threaded function."
# ...
callback()
thr = threading.Thread(target=th_func, args=(cb_func,)).start()
Callback, in thread Thread-1`