Anonymous committed 6494e55

do not kill the local server when it is still used

the client starts a local server if needed. Until now, when it did,
it would also kill it when ending. But meanwhile a different client
might use the same server. New: The client never kills the server.
But when the last client disconnects from a local server, it ends

  • Participants
  • Parent commits c72ca1b

Comments (0)

Files changed (3)

File kajongg/src/

         assert not self.completed
         if result is None:
             # the player has already logged out
-            msg = m18nE('The game server lost connection to player %1')
-            self.table.abort(msg,
+            if request in self.requests:
+                msg = m18nE('The game server lost connection to player %1')
+                self.table.abort(msg,
         failures = [x[1] for x in result if not x[0]]
         if failures:

File kajongg/src/

     # disable warning about too many public methods
     # pylint: disable=R0902
     # we have 11 instance attributes, more than pylint likes
-    serverProcess = None
-    socketServerProcess = None
     def __init__(self, tableList, callback):
                     common.PREF.serverPort = port
                     port = None
-                HumanClient.startLocalServer(self.useSocket, port)
+                self.startLocalServer(port)
                 # give the server up to 5 seconds time to start
                 for loop in range(50):
                     if self.serverListening():
                 return True
-    @staticmethod
-    def startLocalServer(useSocket, port=None):
+    def startLocalServer(self, port):
         """start a local server"""
             if os.path.exists(''):
             if InternalParameters.showSql:
-            if useSocket or == 'nt':
+            if self.useSocket or == 'nt':
             if port:
                 args.append('--port=%d' % port)
-            if useSocket:
+            if self.useSocket:
                 args.append('--db=%slocal.db' % appdataDir())
             process = subprocess.Popen(args,'nt')
             logInfo(m18n('started the local kajongg server: pid=<numid>%1</numid> %2',
       , ' '.join(args)))
-            if useSocket:
-                HumanClient.socketServerProcess = process
-            else:
-                HumanClient.serverProcess = process
         except OSError, exc:
-    @staticmethod
-    def stopLocalServers():
-        """stop the local servers we started"""
-        for process in [HumanClient.serverProcess, HumanClient.socketServerProcess]:
-            if process:
-                logInfo(m18n('stopped the local kajongg server: pid=<numid>%1</numid>',
-                process.terminate()
-        HumanClient.serverProcess = None
-        HumanClient.socketServerProcess = None
-    def __del__(self):
-        """if we go away and we started a local server, stop it again"""
-        HumanClient.stopLocalServers()
     def remote_tablesChanged(self, tables):
         """update table list"""
         Client1.remote_tablesChanged(self, tables)
         if isinstance(result, Failure):
-        HumanClient.stopLocalServers()
         # we may be in a Deferred callback generated in abortGame which would
         # catch sys.exit as an exception
         # and the qt4reactor does not quit the app when being stopped

File kajongg/src/

 from twisted.internet.address import UNIXAddress
 from zope.interface import implements
 from twisted.cred import checkers, portal, credentials, error as credError
+from twisted.internet import reactor
 from game import RemoteGame
 from player import Players
                             self.leaveTable(user, table.tableid)
+        if InternalParameters.socket and not self.users and reactor.running:
+            logInfo('local server terminates. Reason: last client disconnected')
+            reactor.stop()
     def loadSuspendedTables(self, user):
         """loads all yet unloaded suspended tables where this
 def kajonggServer():
     """start the server"""
-    from twisted.internet import reactor
     from optparse import OptionParser
     parser = OptionParser()
     parser.add_option('', '--port', dest='port', help=m18n('the server will listen on PORT'),
         if InternalParameters.socket:
             if == 'nt':
-                logInfo('kajonggserver listening on port %d' % port)
+                logInfo('local server listening on port %d' % port)
                 reactor.listenTCP(port, pb.PBServerFactory(kajonggPortal), interface='')
-                logInfo('kajonggserver listening on UNIX socket %s' % InternalParameters.socket)
+                logInfo('local server listening on UNIX socket %s' % InternalParameters.socket)
                 reactor.listenUNIX(InternalParameters.socket, pb.PBServerFactory(kajonggPortal))
+            logInfo('server listening on port %d' % port)
             reactor.listenTCP(port, pb.PBServerFactory(kajonggPortal))
     except error.CannotListenError, errObj: