2

Suppose we have some asyncio Protocol running. And I need, for example, create Transport to specific socket adress from Protocol handler.

This operation is async. But protocol handler is an ordinary function. We cannot call something like run_until_complete, because loop is already running.

Is there any way to solve this? I hope there is something cleaner, than creating another Task with Queue to it.

uhbif19
  • 3,139
  • 3
  • 26
  • 48
  • 2
    simple approach: https://stackoverflow.com/questions/29126340/calling-a-coroutine-from-asyncio-protocol-data-received and more advance one: https://stackoverflow.com/questions/20746619/calling-coroutines-in-asyncio-protocol-data-received (with comment why) – kwarunek Sep 18 '17 at 07:55
  • @kwarunek Thanks! Now I see, my question is a duplicate. – uhbif19 Sep 18 '17 at 15:52
  • 1
    Maybe somebody find this topic useful: https://stackoverflow.com/questions/30937042/asyncio-persisent-client-protocol-class-using-queue/30940625#30940625 – user24502 Dec 13 '17 at 00:24
  • 1
    Does this answer your question? [Calling a coroutine from asyncio.Protocol.data\_received](https://stackoverflow.com/questions/29126340/calling-a-coroutine-from-asyncio-protocol-data-received) – Rob Gilton Dec 23 '22 at 17:11

0 Answers0