Exemple #1
0
async def poll_client(reader: StreamReader, process: Process, stdin: StreamWriter):
    """
    Continuously waits to receive a stdin message from the client.
    """
    while True:
        (message_type, body) = await read_client(reader)
        if message_type == MESSAGE_STDIN:
            if len(body) == 0:
                stdin.write_eof()
            else:
                stdin.write(body)
        elif message_type == MESSAGE_SIGNAL:
            signal = int.from_bytes(body, "big", signed=False)
            print("Got signal", signal)
            process.send_signal(signal)
Exemple #2
0
async def stop_tunnel(p: Process):
    if p:
        p.send_signal(signal.SIGTERM)
        await p.wait()
        logger.info('Tunnel stopped')