예제 #1
0
파일: test_io.py 프로젝트: xyicheng/thredo
 def test_client(address):
     evt.wait()
     sock = socket(AF_INET, SOCK_STREAM)
     sock.connect(address)
     sock.recv(8)
     s = sock.as_stream()
     try:
         thredo.timeout_after(0.5, s.writelines, line_generator())
     except thredo.ThreadTimeout as e:
         results.append(e.bytes_written)
     sock.close()
예제 #2
0
파일: test_io.py 프로젝트: xyicheng/thredo
 def test_client(address):
     evt.wait()
     sock = socket(AF_INET, SOCK_STREAM)
     sock.connect(address)
     sock.recv(8)
     s = sock.as_stream()
     try:
         msg = b'x'*10000000  # Must be big enough to fill buffers
         thredo.timeout_after(0.5, s.write, msg)
     except thredo.ThreadTimeout as e:
         results.append(e.bytes_written)
     sock.close()
예제 #3
0
def kid():
    while True:
        try:
            print('Can I play?')
            thredo.timeout_after(1, start_evt.wait)
            break
        except thredo.ThreadTimeout:
            print('Wha!?!')

    print('Building the Millenium Falcon in Minecraft')
    with thredo.ThreadGroup() as f:
        f.spawn(friend, 'Max')
        f.spawn(friend, 'Lillian')
        f.spawn(friend, 'Thomas')
        try:
            thredo.sleep(1000)
        except thredo.CancelledError:
            print('Fine. Saving my work.')
            raise
예제 #4
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()
예제 #5
0
파일: test_io.py 프로젝트: xyicheng/thredo
 def server(address):
     sock = socket(AF_INET, SOCK_STREAM)
     sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, True)
     sock.bind(address)
     sock.listen(1)
     evt.set()
     client, addr = sock.accept()
     try:
         client.send(b'OK')
         results.append('handler start')
         s = client.as_stream()
         try:
             thredo.timeout_after(0.5, s.readlines)
         except thredo.ThreadTimeout as e:
             results.extend(e.lines_read)
         results.append('handler done')
     finally:
         client.close()
         sock.close()
예제 #6
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')
예제 #7
0
 def main():
     try:
         with thredo.timeout_after(0.25):
             thredo.sleep(1)
     except thredo.ThreadTimeout:
         result.append('timeout')