Bladeren bron

added a synchronous shutdown method

digital 7 jaren geleden
bovenliggende
commit
8a9cb68a71
1 gewijzigde bestanden met toevoegingen van 9 en 2 verwijderingen
  1. 9 2
      network/__init__.py

+ 9 - 2
network/__init__.py

@@ -272,7 +272,7 @@ class Server(object):
         self.connection_handler = []
         self.connection_handler = []
         # register our cleanup method to be executed when the program exits.
         # 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
         # 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):
     def make_socket(self):
         """
         """
@@ -318,7 +318,14 @@ class Server(object):
             self.socket.bind(self.host)
             self.socket.bind(self.host)
         self.socket.listen(self.max_allowed_clients)
         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.
         This method properly shuts down the sockets and closes them.
         it unregisters itself from atexit, so it doesn't get executed twice
         it unregisters itself from atexit, so it doesn't get executed twice