Python debuggers not included in coroutine?

In the following example:

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() 

I'm trying to get in

loop.create_datagram_endpoint( EchoServerProtocol, local_addr=('127.0.0.1', 9999))

to understand how he behaves. However, when I try to enter the coroutine, the debugger simply jumps over it, as if n were pressed instead of 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> 

Behavior observed with PyCharm IDE (2016 2.3 Community).

I expect to finish here and be able to additionally execute the code.

+5
source share
1 answer

It works if you call await or yield from for your coroutine, e.g.

 listen = await loop.create_datagram_endpoint(EchoServerProtocol, local_addr=('127.0.0.1', 9999)) 

In your example, listen not the result of executing a coroutine, but a coroutine instance . Actual execution is performed by the following line: loop.run_until_complete() .

+4
source

All Articles