示例#1
0
 def body():
     sig = bluelet.Signal()
     handle1 = func1(sig)
     handle2 = func2(sig)
     yield bluelet.spawn(handle1, daemon=False)
     yield bluelet.spawn(handle2, daemon=False)
     yield bluelet.join(handle2)
示例#2
0
 def body():
     sem = bluelet.Semaphore(0)
     handle1 = func1(sem)
     handle2 = func2(sem)
     yield bluelet.spawn(handle1, daemon=False)
     yield bluelet.spawn(handle2, daemon=False)
     yield bluelet.join(handle2)
示例#3
0
 def body():
     cond = bluelet.Condition()
     handle1 = func1(cond)
     handle2 = func2(cond)
     yield bluelet.spawn(handle1, daemon=False)
     yield bluelet.spawn(handle2, daemon=False)
     yield bluelet.join(handle2)
示例#4
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)
示例#5
0
def main():
    ep1, ep2 = yield channel()
    if False:
        # Run in bluelet (i.e., no parallelism).
        yield bluelet.spawn(server(ep1))
        yield bluelet.spawn(client(ep2))
    else:
        # Run in separate processes.
        ta = BlueletProc(server(ep1))
        tb = BlueletProc(client(ep2))
        ta.start()
        tb.start()
        ta.join()
        tb.join()
示例#6
0
文件: ipc.py 项目: ebottabi/bluelet
def main():
    ep1, ep2 = yield channel()
    if False:
        # Run in bluelet (i.e., no parallelism).
        yield bluelet.spawn(server(ep1))
        yield bluelet.spawn(client(ep2))
    else:
        # Run in separate processes.
        ta = BlueletProc(server(ep1))
        tb = BlueletProc(client(ep2))
        ta.start()
        tb.start()
        ta.join()
        tb.join()
示例#7
0
        def body():
            t = time.time()
            res, status = yield bluelet.wait_for(func1(100), timeout=1)
            assert res == False and status is None
            passed = time.time() - t
            assert passed > 1 and passed < 2

            t = time.time()

            # Spawn an interrupt task
            sig = bluelet.Signal()
            sig.clear()
            handle = interrupt_func(sig, 0.5)
            yield bluelet.spawn(handle, daemon=False)

            res, status = yield bluelet.wait_for(func1(1),
                                                 timeout=2,
                                                 interrupt=sig)
            assert res == False and status == None
            passed = time.time() - t
            assert passed > 0.5 and passed < 1
            yield bluelet.kill(handle)

            t = time.time()
            res, status = yield bluelet.wait_for(func1(0.5), timeout=1)
            assert res == True and status == 1
            passed = time.time() - t
            assert passed > 0.5 and passed < 1
示例#8
0
def echoserver():
    listener = bluelet.Listener('', 4915)
    try:
        while True:
            conn = yield listener.accept()
            yield bluelet.spawn(echoer(conn))
    except KeyboardInterrupt:
        print()
    finally:
        print('Exiting.')
        listener.close()
示例#9
0
 def scheduler(self):
     while self.run:
         if not self.pipe.poll():
             yield bluelet.null()
             if self.run_scheduling:
                 if len(self.engines_idle) > 0 and len(self.jobs_idle) > 0:
                     yield bluelet.spawn(self.schedule_job())
         else:
             recv = self.pipe.recv()
             BCK.__dict__[recv[0]](self, *recv[1:])
     yield bluelet.end()
示例#10
0
文件: echo.py 项目: rdhyee/bluelet
def echoserver():
    listener = bluelet.Listener('', 4915)
    try:
        while True:
            conn = yield listener.accept()
            yield bluelet.spawn(echoer(conn))
    except KeyboardInterrupt:
        print
    finally:
        print 'Exiting.'
        listener.close()
示例#11
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)
示例#12
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)
示例#13
0
def channel(port=4915):
    # Create a pair of connected sockets.
    connections = [None, None]
    listener = bluelet.Listener('127.0.0.1', port)

    def listen():
        connections[0] = yield listener.accept()  # Avoiding nonlocal.
    listen_thread = listen()
    yield bluelet.spawn(listen_thread)

    connections[1] = yield bluelet.connect('127.0.0.1', port)

    yield bluelet.join(listen_thread)

    # Wrap sockets in Endpoints.
    sentinel = uuid.uuid4().bytes  # Somewhat hacky...
    yield bluelet.end((Endpoint(connections[0], sentinel),
                       Endpoint(connections[1], sentinel)))
示例#14
0
文件: ipc.py 项目: ebottabi/bluelet
def channel(port=4915):
    # Create a pair of connected sockets.
    connections = [None, None]
    listener = bluelet.Listener('127.0.0.1', port)

    def listen():
        connections[0] = yield listener.accept()  # Avoiding nonlocal.
    listen_thread = listen()
    yield bluelet.spawn(listen_thread)

    connections[1] = yield bluelet.connect('127.0.0.1', port)

    yield bluelet.join(listen_thread)

    # Wrap sockets in Endpoints.
    sentinel = uuid.uuid4().bytes  # Somewhat hacky...
    yield bluelet.end((Endpoint(connections[0], sentinel),
                       Endpoint(connections[1], sentinel)))
示例#15
0
 def crawl():
     for username in USERNAMES:
         yield bluelet.spawn(fetch(username))
示例#16
0
def sleepy():
    for i in (0, 1, 3, 5):
        yield bluelet.spawn(sleeper(i))
示例#17
0
def exc_grandparent():
    yield bluelet.spawn(exc_parent())
示例#18
0
文件: crawler.py 项目: rdhyee/bluelet
 def crawl():
     for username in USERNAMES:
         yield bluelet.spawn(fetch(username))
示例#19
0
def sleepy():
    for i in (0, 1, 3, 5):
        yield bluelet.spawn(sleeper(i))
示例#20
0
def main():
    yield bluelet.spawn(connecho())