Пример #1
0
 def main():
     serv = thredo.spawn(server, ('', 25000))
     client = thredo.spawn(test_client, ('localhost', 25000))
     thredo.sleep(0.1)
     client.cancel()
     start.set()
     serv.join()
Пример #2
0
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()
Пример #3
0
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)
Пример #4
0
 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__))
Пример #5
0
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()
Пример #6
0
 def main():
     lock.acquire()
     try:
         t = thredo.spawn(child)
         result.append('parent')
         t.cancel()
     finally:
         lock.release()
Пример #7
0
 def main():
     lock.acquire()
     result.append(lock.value)
     try:
         t = thredo.spawn(child)
         result.append('parent')
     finally:
         lock.release()
     t.join()
Пример #8
0
 def main():
     lock.acquire()
     if lock.locked():
         result.append('locked')
     try:
         t = thredo.spawn(child)
         result.append('parent')
     finally:
         lock.release()
     t.join()
Пример #9
0
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()
Пример #10
0
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')
Пример #11
0
 def main():
     q = thredo.Queue()
     t = thredo.spawn(consumer, q)
     results.append('start')
     t.cancel()
Пример #12
0
 def main():
     t = thredo.spawn(child)
     thredo.sleep(0.1)
     t.cancel()
Пример #13
0
def main():
    q = thredo.Queue(maxsize=1)
    t1 = thredo.spawn(consumer, q)
    t2 = thredo.spawn(producer, q, 1000)
    t1.join()
    t2.join()
Пример #14
0
 def main():
     serv = thredo.spawn(server, ('',25000))
     client = thredo.spawn(test_client, ('localhost', 25000))
     serv.join()
     client.join()
Пример #15
0
def main():
    t = thredo.spawn(func)
    thredo.sleep(2)
    t.cancel()
Пример #16
0
 def main():
     t1 = thredo.spawn(incr, 10000)
     t2 = thredo.spawn(decr, 10000)
     evt.set()
     t1.join()
     t2.join()
Пример #17
0
 def main():
     t = thredo.spawn(waiter)
     result.append('start')
     t.cancel()
Пример #18
0
def main():
    t = thredo.spawn(func, 2, '3')
    try:
        print('Result:', t.join())
    except thredo.ThreadError as e:
        print('Failed:', repr(e.__cause__))
Пример #19
0
 def main():
     t1 = thredo.spawn(waiter)
     t2 = thredo.spawn(producer)
     t1.join()
     t2.join()
Пример #20
0
def main():
    t = thredo.spawn(func, 2, 3)
    print("Result:", t.join())
Пример #21
0
 def main():
     t = thredo.spawn(basic_thread, 2, 2)
     result.append(t.join())
Пример #22
0
def main():
    t = thredo.spawn(hello, 100)
    thredo.sleep(5)
    t.cancel()
    print("Goodbye")
Пример #23
0
 def main():
     q = thredo.Queue()
     t1 = thredo.spawn(consumer, q)
     t2 = thredo.spawn(producer, q)
     t1.join()
     t2.join()
Пример #24
0
 def main():
     t = thredo.spawn(waiter)
     result.append('start')
     evt.set()
     t.join()
Пример #25
0
 def main():
     q = thredo.Queue(maxsize=1)
     t = thredo.spawn(producer, q)
     results.append('start')
     thredo.sleep(0.1)
     t.cancel()
Пример #26
0
def main():
    t = thredo.spawn(func, 2, 3)
    result = t.join()
    print('Result:', result)