b2bua icon indicating copy to clipboard operation
b2bua copied to clipboard

[Off-topic]Ghost of Twisted - sippy_async - monkey patch to support running on anyio

Open space88man opened this issue 3 years ago • 0 comments

Introducing sippy_async: a monkey patch to run the event loop over anyio 3, which means that the loop will support asyncio or trio.

I realised that this repo had moved from Twisted to a hand-crafted libelperiodic loop, but... if you are using async python, I have an experimental monkey patch to support running the event loop on asyncio/trio via anyio. Basic tests that pass: Timeout, Udp_server.

# runs the Timeout / Udp_server testsuites under anyio
python -m sippy_async

Implementation notes:

  • does not use threads and the UDP server is implemented with anyio classes
  • ED2.callFromThread() is not implemented as the network servers run on the event loop
  • not all methods of Udp_server and EventDispatcher are implemented; only enough to run simple B2BUA scripts and some tests
  • anyio has sync/async-type queues("memory object streams"): this enables callbacks that require async functionality ( UDP data transmission, timeouts) to work without async creep; no function signatures are changed
  • the curio async framework is not supported as this restriction is imposed by anyio 3

The pro would be that if you want to write your B2BUA scripts with async python you won't need to run two event loops.

space88man avatar May 17 '21 04:05 space88man