def main(): serv = thredo.spawn(server, ('', 25000)) client = thredo.spawn(test_client, ('localhost', 25000)) thredo.sleep(0.1) client.cancel() start.set() serv.join()
def main(): lck = thredo.Semaphore() t1 = thredo.spawn(func, lck, 'thread-1') t2 = thredo.spawn(func, lck, 'thread-2') # Case 2: Cancel a thread holding a lock thredo.sleep(2) t1.cancel() t2.join()
def echo_server(host, port): sock = socket(AF_INET, SOCK_STREAM) sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) sock.bind((host, port)) sock.listen(5) while True: client, addr = sock.accept() t = thredo.spawn(echo_handler, client, addr, daemon=True) thredo.spawn(killer, 30, t)
def main(): t = thredo.spawn(basic_thread, 2, '2') try: t.join() except thredo.ThreadError as e: result.append('error') result.append(type(e.__cause__))
def main(): # serv = ThredoTCPServer(('', 25000), EchoHandler) serv = ThredoTCPServer(('', 25000), EchoStreamHandler) serv.allow_reuse_address = True t = thredo.spawn(serv.serve_forever) thredo.SignalEvent(signal.SIGINT).wait() print('Cancelling') t.cancel()
def main(): lock.acquire() try: t = thredo.spawn(child) result.append('parent') t.cancel() finally: lock.release()
def main(): lock.acquire() result.append(lock.value) try: t = thredo.spawn(child) result.append('parent') finally: lock.release() t.join()
def main(): lock.acquire() if lock.locked(): result.append('locked') try: t = thredo.spawn(child) result.append('parent') finally: lock.release() t.join()
def main(): phils = [thredo.spawn(philosopher, n) for n in range(5)] try: with thredo.timeout_after(10): for p in phils: p.wait() except thredo.ThreadTimeout: phils[random.randint(0, 4)].cancel() for p in phils: p.wait()
def parent(): goodbye = thredo.SignalEvent(signal.SIGINT, signal.SIGTERM) kid_task = thredo.spawn(kid) thredo.sleep(5) print("Yes, go play") start_evt.set() goodbye.wait() del goodbye print("Let's go") count_task = thredo.spawn(countdown, 10) count_task.join() print("We're leaving!") try: thredo.timeout_after(10, kid_task.join) except thredo.ThreadTimeout: kid_task.cancel() thredo.sleep(3) print('Parent Leaving')
def main(): q = thredo.Queue() t = thredo.spawn(consumer, q) results.append('start') t.cancel()
def main(): t = thredo.spawn(child) thredo.sleep(0.1) t.cancel()
def main(): q = thredo.Queue(maxsize=1) t1 = thredo.spawn(consumer, q) t2 = thredo.spawn(producer, q, 1000) t1.join() t2.join()
def main(): serv = thredo.spawn(server, ('',25000)) client = thredo.spawn(test_client, ('localhost', 25000)) serv.join() client.join()
def main(): t = thredo.spawn(func) thredo.sleep(2) t.cancel()
def main(): t1 = thredo.spawn(incr, 10000) t2 = thredo.spawn(decr, 10000) evt.set() t1.join() t2.join()
def main(): t = thredo.spawn(waiter) result.append('start') t.cancel()
def main(): t = thredo.spawn(func, 2, '3') try: print('Result:', t.join()) except thredo.ThreadError as e: print('Failed:', repr(e.__cause__))
def main(): t1 = thredo.spawn(waiter) t2 = thredo.spawn(producer) t1.join() t2.join()
def main(): t = thredo.spawn(func, 2, 3) print("Result:", t.join())
def main(): t = thredo.spawn(basic_thread, 2, 2) result.append(t.join())
def main(): t = thredo.spawn(hello, 100) thredo.sleep(5) t.cancel() print("Goodbye")
def main(): q = thredo.Queue() t1 = thredo.spawn(consumer, q) t2 = thredo.spawn(producer, q) t1.join() t2.join()
def main(): t = thredo.spawn(waiter) result.append('start') evt.set() t.join()
def main(): q = thredo.Queue(maxsize=1) t = thredo.spawn(producer, q) results.append('start') thredo.sleep(0.1) t.cancel()
def main(): t = thredo.spawn(func, 2, 3) result = t.join() print('Result:', result)