def _parallel_split(obj, eng, calls): lock=thread.allocate_lock() i = 0 eng.setVar('lock', lock) for func in calls: new_eng = duplicate_engine_instance(eng) new_eng.setWorkflow([lambda o,e: e.setVar('lock', lock), func]) thread.start_new_thread(new_eng.process, ([obj], ))
def _parallel_split(obj, eng, calls): lock = thread.allocate_lock() i = 0 eng.setVar('lock', lock) for func in calls: new_eng = duplicate_engine_instance(eng) new_eng.setWorkflow([lambda o, e: e.setVar('lock', lock), func]) thread.start_new_thread(new_eng.process, ([obj], ))
def _synchronize(obj, eng): queue = MyTimeoutQueue() #spawn a pool of threads, and pass them queue instance for i in range(len(args)-1): t = MySpecialThread(queue) t.setDaemon(True) t.start() for func in args[0:-1]: if isinstance(func, list) or isinstance(func, tuple): new_eng = duplicate_engine_instance(eng) new_eng.setWorkflow(func) queue.put(lambda: new_eng.process([obj])) else: queue.put(lambda: func(obj, eng)) #wait on the queue until everything has been processed queue.join_with_timeout(timeout) #run the last func args[-1](obj, eng)
def _synchronize(obj, eng): queue = MyTimeoutQueue() # spawn a pool of threads, and pass them queue instance for i in range(len(args) - 1): t = MySpecialThread(queue) t.setDaemon(True) t.start() for func in args[0:-1]: if isinstance(func, list) or isinstance(func, tuple): new_eng = duplicate_engine_instance(eng) new_eng.setWorkflow(func) queue.put(lambda: new_eng.process([obj])) else: queue.put(lambda: func(obj, eng)) # wait on the queue until everything has been processed queue.join_with_timeout(timeout) # run the last func args[-1](obj, eng)
def x(obj, eng): if isinstance(call, list) or isinstance(call, tuple): new_eng = duplicate_engine_instance(eng) new_eng.setWorkflow(call) profileit = lambda: new_eng.process([obj]) else: profileit = lambda: call(obj, eng) if output: cProfile.runctx('profileit()', globals(), locals(), output) else: cProfile.runctx('profileit()', globals(), locals()) if output and stats: for st in stats: fname = '%s.stats-%s' % (output, st) fo = open(fname, 'w') p = pstats.Stats(output, stream=fo) p.strip_dirs() p.sort_stats(st) p.print_stats() fo.close()