def body(): lock = bluelet.Lock() handle1 = func1(lock) handle2 = func2(lock) yield bluelet.spawn(handle1) yield bluelet.spawn(handle2) yield bluelet.sleep(1) yield bluelet.kill(handle1) yield bluelet.sleep(1) yield bluelet.join(handle2)
def main_coro(self): handler = self.handle_results(self.callback) yield bluelet.spawn(handler) # Poll for thread shutdown. while True: yield bluelet.sleep(1) with self.shutdown_lock: if self.shutdown: break # Halt the handler thread. yield bluelet.kill(handler)
def sleeper(duration): print('Going to sleep for %i seconds...' % duration) yield bluelet.sleep(duration) print('...woke up after %i seconds.' % duration)
def interrupt_func(sig, param): yield bluelet.sleep(param) yield sig.set()
def func1(param): yield bluelet.sleep(param) yield bluelet.end(1)
def func2(lock): yield bluelet.sleep(1) yield lock.acquire() yield bluelet.sleep(1) yield lock.release()
def func1(cond): yield bluelet.sleep(3) yield cond.acquire() yield cond.notify_all() yield cond.release()
def func1(sem): yield bluelet.sleep(3) yield sem.release()
def func1(sig): yield bluelet.sleep(3) yield sig.set()
#!/bin/env python3 import bluelet, sys, time, itertools, functools, tempfile, os from multiprocessing import Process, Pipe, Manager, SimpleQueue from Pager import Pager from Job import Jobs from Fmt import Args, expand_jobs from Bck import BCK, Engine, Msg, Ready, Piper #from numpy import random # add_job(Jobs(Fmt('sleep %p').sub(p = map(str,random.random_integers(1,10,20).tolist())))); #bluelet.null = (lambda f: lambda: (time.sleep(0.01), (yield f())))(bluelet.null) bluelet.null = lambda: bluelet.sleep(0.02) usage = \ """usage: %s --profile=<profile> where <profile> corresponds to ~/.ipython/profile_<profile>""" # decorator def toplevel_and_alive(method): def _method(*args, **kwargs): if _hq.thread_bck.is_alive(): method(_hq, *args, **kwargs) else: print('background thread is not alive') globals()[method.__name__] = _method return method class HQ: def __init__(self, profile):