Wednesday, March 19, 2008

thread module provides an easy way for parallel execution of your functions in Python:

def a_function(args):
import thread
lock1=thread.allocate_lock()

lock2.acquire()

thread.start_new_thread(function1, (someargs, lock1))

lock2=thread.allocate_lock()

lock2.acquire()

thread.start_new_thread(function1, (someargs, lock2))

lock1.acquire()

lock2.acquire()

print 'Both threads finished'

function2(someargs)

0 Comments:

Post a Comment

<< Home