def shutDown(self):
     self.running = 0
     self.awakeSelect()
     self._shuttingdown = 1  #jsl-is this used anywhere?
     print "ThreadedAppServer: Shutting Down"
     self.mainsocket.close()
     for i in range(self.threadCount):
         self.requestQueue.put(None)  #kill all threads
     for i in self.threadPool:
         try:
             i.join()
         except:
             pass
     AppServer.shutDown(self)
Ejemplo n.º 2
0
	def shutDown(self):
		"""Called on shutdown.

		Also calls `AppServer.shutDown`, but first closes all sockets
		and tells all the threads to die.

		"""
		print "ThreadedAppServer is shutting down..."
		if self._running > 2:
			self._running = 2 # ask main loop to finish
			self.awakeSelect() # unblock select call in mainloop()
			sys.stdout.flush()
			for i in range(30): # wait at most 3 seconds for shutdown
				if self._running < 2:
					break
				time.sleep(0.1)
		if self._sockets:
			# Close all sockets now:
			for sock in self._sockets.values():
				sock.close()
		if self._socketHandlers:
			# Remove the text files with the server addresses:
			for handler in self._socketHandlers.values():
				adrFile = self.addressFileName(handler)
				if os.path.exists(adrFile):
					try:
						os.unlink(adrFile)
					except OSError:
						print "Warning: Could not remove", adrFile
		# Tell all threads to end:
		for i in range(self._threadCount):
			self._requestQueue.put(None)
		for i in self._threadPool:
			try:
				i.join()
			except Exception:
				pass
		# Call super's shutdown:
		AppServer.shutDown(self)
Ejemplo n.º 3
0
 def shutDown(self):
     self._running = 0
     print "CgiPlusAppServer: Shutting Down"
     AppServer.shutDown(self)
Ejemplo n.º 4
0
    def shutDown(self):
        """Called on shutdown.

        Also calls `AppServer.shutDown`, but first closes all sockets
        and tells all the threads to die.
        """
        print "ThreadedAppServer is shutting down..."
        if self._running > 2:
            self._running = 2  # ask main loop to finish
            self.awakeSelect()  # unblock select call in mainloop()
            sys.stdout.flush()
            for i in range(30):  # wait at most 3 seconds for shutdown
                if self._running < 2:
                    break
                sleep(0.1)
        if self._sockets:
            # Close all sockets now:
            for sock in self._sockets.values():
                sock.close()
        if self._socketHandlers:
            # Remove the text files with the server addresses:
            for handler in self._socketHandlers.values():
                adrFile = self.addressFileName(handler)
                if os.path.exists(adrFile):
                    try:
                        os.unlink(adrFile)
                    except (AttributeError, OSError):
                        print "Warning: Could not remove", adrFile
        # Tell all threads to end:
        for i in range(self._threadCount):
            self._requestQueue.put(None)
        # Join all threads:
        closeTime = time() + 3
        for t in self._threadPool:
            timeout = max(0.1, closeTime - time())
            try:
                t.join(timeout)
            except Exception:
                pass
        # Check whether all threads have ended:
        for t in self._threadPool:
            if t.isAlive():
                if debug:
                    print "Hanging worker thread", t.threadID()
                running = True
                break
        else:
            running = False
        if running:
            # Abort all remaining threads:
            print "Aborting hanging worker threads..."
            for t in self._threadPool:
                if t.isAlive():
                    t.abort(ServerShutDownError)
            # Join remaining threads:
            closeTime = time() + 3
            for t in self._threadPool:
                if t.isAlive():
                    timeout = max(0.1, closeTime - time())
                    try:
                        t.join(timeout)
                    except Exception:
                        pass
            # Check whether remaining threads have ended:
            for t in self._threadPool:
                if t.isAlive():
                    if debug:
                        print "Warning: Could not abort thread", t.threadID()
                    else:
                        print "Warning: Could not abort all worker threads"
                    break
            else:
                print "Hanging worker threads have been aborted."
                running = False
        # Call super's shutdown:
        AppServer.shutDown(self)