summaryrefslogtreecommitdiffstats
path: root/Lib/socketserver.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-04-13 00:36:52 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-04-13 00:36:52 (GMT)
commit0cab9c1ebaa11bb7838a552c671c903156262ab7 (patch)
tree640bcabc8876c74c7ba53231551613cfb9a34600 /Lib/socketserver.py
parent7258176c68a5061a5d05ee43f11e99fd94e34364 (diff)
downloadcpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.zip
cpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.tar.gz
cpython-0cab9c1ebaa11bb7838a552c671c903156262ab7.tar.bz2
Issue #26404: Add context manager to socketserver, by Aviv Palivoda
Diffstat (limited to 'Lib/socketserver.py')
-rw-r--r--Lib/socketserver.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index 2f39514..3e1f058 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -378,6 +378,12 @@ class BaseServer:
traceback.print_exc()
print('-'*40, file=sys.stderr)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self.server_close()
+
class TCPServer(BaseServer):