Skip to content

Instantly share code, notes, and snippets.

View smurfix's full-sized avatar
💭
Trio+Asterisk-ARI

Matthias Urlichs smurfix

💭
Trio+Asterisk-ARI
View GitHub Profile
class EnterTimeout:
def __init__(self, async_cm, timeout):
self._async_cm = async_cm
self._timeout = timeout
async def __aenter__(self):
with fail_after(self.timeout):
return await self._async_cm.__aenter__()
async def __aexit__(self, *args):
@smurfix
smurfix / mux.py
Last active September 7, 2021 08:33
example code for a multiplexing client/server protocol
#!/usr/bin/python3
"""
This is example code for a multiplexing client/server protocol.
Missing:
* server capacity management
* actual testcases for error propagation and cancellation
* handle badly-formatted messages without crashing the server
* sending more than one request or reply per interaction
@vxgmichel
vxgmichel / trio-asyncgen-writeup.md
Last active November 22, 2018 13:24
Using trio nurseries inside async generators

Using trio nurseries inside async generators

From what I've read in this comment (issue #264), it seems like the idea of:

  • allowing yield inside a trio nursery
  • AND allowing it to cancel the current task regardless of its current position in the code

is out of the picture. The main argument against that is presented in this comment (issue 638):