Python 调试器没有进入协程?
Python debuggers not stepping into a coroutine?
在下面的例子中:
import asyncio
import ipdb
class EchoServerProtocol:
def connection_made(self, transport):
self.transport = transport
def datagram_received(self, data, addr):
message = data.decode()
print('Received %r from %s' % (message, addr))
print('Send %r to %s' % (message, addr))
self.transport.sendto(data, addr)
loop = asyncio.get_event_loop()
ipdb.set_trace(context=21)
print("Starting UDP server")
# One protocol instance will be created to serve all client requests
listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
transport, protocol = loop.run_until_complete(listen)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
transport.close()
loop.close()
我正在尝试进入
loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
了解它的内部行为。
但是,当我尝试进入协程时,调试器只是跳过它,就好像按下了 n
而不是 s
.
> ../async_test.py(18)<module>()
17 # One protocol instance will be created to serve all client requests
---> 18 listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
19 transport, protocol = loop.run_until_complete(listen)
ipdb> s
> ../async_test.py(19)<module>()
18 listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
---> 19 transport, protocol = loop.run_until_complete(listen)
20
ipdb>
PyCharm(2016 2.3 社区)IDE.
遇到此行为
我希望结束 here 并能够额外地逐步执行代码。
如果你为你的协程调用 await
或 yield from
它会起作用,比如
listen = await loop.create_datagram_endpoint(EchoServerProtocol,
local_addr=('127.0.0.1', 9999))
在您的示例中,listen
不是协程执行的结果,而是 协程实例 本身。
实际执行由下一行执行:loop.run_until_complete()
.
在下面的例子中:
import asyncio
import ipdb
class EchoServerProtocol:
def connection_made(self, transport):
self.transport = transport
def datagram_received(self, data, addr):
message = data.decode()
print('Received %r from %s' % (message, addr))
print('Send %r to %s' % (message, addr))
self.transport.sendto(data, addr)
loop = asyncio.get_event_loop()
ipdb.set_trace(context=21)
print("Starting UDP server")
# One protocol instance will be created to serve all client requests
listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
transport, protocol = loop.run_until_complete(listen)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
transport.close()
loop.close()
我正在尝试进入
loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
了解它的内部行为。
但是,当我尝试进入协程时,调试器只是跳过它,就好像按下了 n
而不是 s
.
> ../async_test.py(18)<module>()
17 # One protocol instance will be created to serve all client requests
---> 18 listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
19 transport, protocol = loop.run_until_complete(listen)
ipdb> s
> ../async_test.py(19)<module>()
18 listen = loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))
---> 19 transport, protocol = loop.run_until_complete(listen)
20
ipdb>
PyCharm(2016 2.3 社区)IDE.
遇到此行为我希望结束 here 并能够额外地逐步执行代码。
如果你为你的协程调用 await
或 yield from
它会起作用,比如
listen = await loop.create_datagram_endpoint(EchoServerProtocol,
local_addr=('127.0.0.1', 9999))
在您的示例中,listen
不是协程执行的结果,而是 协程实例 本身。
实际执行由下一行执行:loop.run_until_complete()
.