Re: [Twisted-Python] Asynchronous code in a context manager

2018-03-23 Thread meejah
Are you using Python3? Then there's "asynchronous context managers". I finally found a use-case for one in txtorcon, so here's an example: http://txtorcon.readthedocs.io/en/latest/txtorcon-controller.html#txtorcon.Tor.onion_authentication -- meejah

[Twisted-Python] Asynchronous code in a context manager

2018-03-23 Thread Peter Westlake
I have a context manager whose __exit__ method needs to run some asynchronous Twisted code. Using Crochet's @wait_for very nearly works: no_setup() class Example(object): def __exit__(t, v, tb): return self.cleanup() @wait_for @inlineCallbacks def cleanup(self):