Browse Source

added a synchronous shutdown method

digital 7 years ago
parent
commit
8a9cb68a71
1 changed files with 9 additions and 2 deletions
  1. 9 2
      network/__init__.py

+ 9 - 2
network/__init__.py

@@ -272,7 +272,7 @@ class Server(object):
         self.connection_handler = []
         # register our cleanup method to be executed when the program exits.
         # the cleanup function unregisters itself, so it won't get executed twice when the user called it befor the program exites
-        atexit.register(self.shutdown)
+        atexit.register(self.sync_shutdown)
 
     def make_socket(self):
         """
@@ -318,7 +318,14 @@ class Server(object):
             self.socket.bind(self.host)
         self.socket.listen(self.max_allowed_clients)
 
-    def shutdown(self):
+    def sync_shutdown(self):
+        """
+        this method can be called synchronous and calls the asynchronous
+        shutdown method.
+        """
+        curio.run(self.shutdown)
+
+    async def shutdown(self):
         """
         This method properly shuts down the sockets and closes them.
         it unregisters itself from atexit, so it doesn't get executed twice