From 84f75551a31047a32d0dc0c2c7a91135e68b0d9f Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 20 Jan 2019 22:53:32 +0000 Subject: [PATCH] core: make Receiver a self-closing context manager. --- mitogen/core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index c95a9b0c..223e17f6 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -813,6 +813,12 @@ class Receiver(object): def __repr__(self): return 'Receiver(%r, %r)' % (self.router, self.handle) + def __enter__(self): + return self + + def __exit__(self, _1, _2, _3): + self.close() + def to_sender(self): """ Return a :class:`Sender` configured to deliver messages to this