Skip to content

Instantly share code, notes, and snippets.

@P8H
Created December 8, 2015 08:28
Show Gist options
  • Save P8H/a0804fb57422c9e79fb2 to your computer and use it in GitHub Desktop.
Save P8H/a0804fb57422c9e79fb2 to your computer and use it in GitHub Desktop.
Python BaseManager: stop serve_forever
from multiprocessing.managers import BaseManager
class IPC(BaseManager):
"""Little example how to provide a shutdown() function if you us the serve_forever method
"""""
_server_object = None # docs.python.org/3.5/library/multiprocessing.html#multiprocessing.managers.BaseManager
def __init__(self):
BaseManager.__init__(self, address=('127.0.0.1', 4000), authkey=b'42')
def start_ipc_server(self, server, serve_forever: bool=False):
# self.register('some_objects', server)
self._server_object = self.get_server()
self._server_object.serve_forever()
def shutdown(self):
self._server_object.stop_event.set()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment