Example #1
0
 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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
def sleeper(duration):
    print('Going to sleep for %i seconds...' % duration)
    yield bluelet.sleep(duration)
    print('...woke up after %i seconds.' % duration)
Example #5
0
 def interrupt_func(sig, param):
     yield bluelet.sleep(param)
     yield sig.set()
Example #6
0
 def func1(param):
     yield bluelet.sleep(param)
     yield bluelet.end(1)
Example #7
0
 def func2(lock):
     yield bluelet.sleep(1)
     yield lock.acquire()
     yield bluelet.sleep(1)
     yield lock.release()
Example #8
0
 def func1(cond):
     yield bluelet.sleep(3)
     yield cond.acquire()
     yield cond.notify_all()
     yield cond.release()
Example #9
0
 def func1(sem):
     yield bluelet.sleep(3)
     yield sem.release()
Example #10
0
 def func1(sig):
     yield bluelet.sleep(3)
     yield sig.set()
Example #11
0
def sleeper(duration):
    print('Going to sleep for %i seconds...' % duration)
    yield bluelet.sleep(duration)
    print('...woke up after %i seconds.' % duration)
Example #12
0
#!/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):