asyncio DatagramProtocol不会打印到控制台,但会在sublime文本窗口中打印

时间:2018-03-02 01:30:33

标签: python sublimetext3 stdout python-3.6 python-asyncio

我有以下最小客户端代码:

inset into result_table select (put here the query)

在我的控制台中,当我运行class Client(asyncio.DatagramProtocol): def connection_made(self, transport): print(transport) self._transport = transport req = { 'action': 'join', 'x': 123, 'y': list(range(5)) } self._transport.sendto( dumps(req) # dumps is bencode the dict ) print('sent join') def connection_lost(self, exc): print('lost') loop = asyncio.get_event_loop() loop.stop() raise exc def error_received(self, exc): raise exc def datagram_received(self, data, addr): print('addr', addr) data = parse_packet(data) with open('f', 'a+') as fp: fp.write(str(data) + '\n') print(data) if __name__ == "__main__": loop = asyncio.get_event_loop() listener = loop.create_datagram_endpoint( Client, remote_addr=('127.0.0.1', 9999) ) transport, protocol = loop.run_until_complete(listener) loop.run_forever() transport.close() loop.close() 时,控制台中没有显示上面的client.py语句。但是,我的UDP服务器发送的数据正在客户端正确接收。文件print包含服务器发送的内容。

当在Sublime Text窗口中运行时(使用 F7 Ctrl + B ),相同的程序在构建结果窗口中显示打印语句。

0 个答案:

没有答案