diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-04-13 00:36:52 +0000 |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-04-13 00:36:52 +0000 |
commit | 0cab9c1ebaa11bb7838a552c671c903156262ab7 (patch) | |
tree | 640bcabc8876c74c7ba53231551613cfb9a34600 /Lib/xmlrpc/server.py | |
parent | 7258176c68a5061a5d05ee43f11e99fd94e34364 (diff) | |
download | cpython-git-0cab9c1ebaa11bb7838a552c671c903156262ab7.tar.gz |
Issue #26404: Add context manager to socketserver, by Aviv Palivoda
Diffstat (limited to 'Lib/xmlrpc/server.py')
-rw-r--r-- | Lib/xmlrpc/server.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index 5b5bf7c405..78728f271c 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -971,16 +971,15 @@ if __name__ == '__main__': def getCurrentTime(): return datetime.datetime.now() - server = SimpleXMLRPCServer(("localhost", 8000)) - server.register_function(pow) - server.register_function(lambda x,y: x+y, 'add') - server.register_instance(ExampleService(), allow_dotted_names=True) - server.register_multicall_functions() - print('Serving XML-RPC on localhost port 8000') - print('It is advisable to run this example server within a secure, closed network.') - try: - server.serve_forever() - except KeyboardInterrupt: - print("\nKeyboard interrupt received, exiting.") - server.server_close() - sys.exit(0) + with SimpleXMLRPCServer(("localhost", 8000)) as server: + server.register_function(pow) + server.register_function(lambda x,y: x+y, 'add') + server.register_instance(ExampleService(), allow_dotted_names=True) + server.register_multicall_functions() + print('Serving XML-RPC on localhost port 8000') + print('It is advisable to run this example server within a secure, closed network.') + try: + server.serve_forever() + except KeyboardInterrupt: + print("\nKeyboard interrupt received, exiting.") + sys.exit(0) |