예제 #1
0
def select_and_recv(conn, expected_char=None):
    """Wait for the given Connection to have data to receive, and return it.
    If a character is provided check its correct before returning it."""
    # Must use cothread's select if cothread is present, otherwise we'd block
    # processing on all cothread processing. But we don't want to use it
    # unless we have to, as importing cothread can cause issues with forking.
    if "cothread" in sys.modules:
        from cothread import select
        rrdy, _, _ = select([conn], [], [], TIMEOUT)
    else:
        # Would use select.select(), but Windows doesn't accept Pipe handles
        # as selectable objects.
        if conn.poll(TIMEOUT):
            rrdy = True

    if rrdy:
        val = conn.recv()
    else:
        pytest.fail("Did not receive expected char before TIMEOUT expired")

    if expected_char:
        assert val == expected_char, \
            "Expected character did not match"

    return val
예제 #2
0
def testSelect():
    r, w = os.pipe()
    Reset()
    for i in range(5):
        select([r, w], [w], [], 1)
예제 #3
0
 def Waiter():
     while True:
         cothread.select([r], [], [])
         rx = os.read(r, 1)
         print('read', rx)
예제 #4
0
 def Waiter():
     while True:
         cothread.select([r], [], [])
         rx = os.read(r, 1)
         print('read', rx)
예제 #5
0
def testSelect():
    r, w = os.pipe()
    Reset()
    for i in range(5):
        select([r, w], [w], [], 1)