Back to index

moin  1.9.0~rc2
Public Member Functions | Private Member Functions | Private Attributes
MoinMoin.support.flup.server.threadedserver.ThreadedServer Class Reference

List of all members.

Public Member Functions

def __init__
def run
def shutdown

Private Member Functions

def _mainloopPeriodic
def _exit
def _isClientAllowed
def _hupHandler
def _intHandler
def _installSignalHandlers
def _restoreSignalHandlers

Private Attributes

 _jobClass
 _jobArgs
 _threadPool
 _keepGoing
 _hupReceived
 _oldSIGs

Detailed Description

Definition at line 49 of file threadedserver.py.


Constructor & Destructor Documentation

def MoinMoin.support.flup.server.threadedserver.ThreadedServer.__init__ (   self,
  jobClass = None,
  jobArgs = (),
  kw 
)

Definition at line 50 of file threadedserver.py.

00050 
00051     def __init__(self, jobClass=None, jobArgs=(), **kw):
00052         self._jobClass = jobClass
00053         self._jobArgs = jobArgs
00054 
00055         self._threadPool = ThreadPool(**kw)


Member Function Documentation

def MoinMoin.support.flup.server.threadedserver.ThreadedServer._exit (   self,
  reload = False 
) [private]
Protected convenience method for subclasses to force an exit. Not
really thread-safe, which is why it isn't public.

Definition at line 124 of file threadedserver.py.

00124 
00125     def _exit(self, reload=False):
00126         """
00127         Protected convenience method for subclasses to force an exit. Not
00128         really thread-safe, which is why it isn't public.
00129         """
00130         if self._keepGoing:
00131             self._keepGoing = False
00132             self._hupReceived = reload

def MoinMoin.support.flup.server.threadedserver.ThreadedServer._hupHandler (   self,
  signum,
  frame 
) [private]

Definition at line 139 of file threadedserver.py.

00139 
00140     def _hupHandler(self, signum, frame):
00141         self._hupReceived = True
00142         self._keepGoing = False

Definition at line 146 of file threadedserver.py.

00146 
00147     def _installSignalHandlers(self):
00148         supportedSignals = [signal.SIGINT, signal.SIGTERM]
00149         if hasattr(signal, 'SIGHUP'):
00150             supportedSignals.append(signal.SIGHUP)
00151 
00152         self._oldSIGs = [(x,signal.getsignal(x)) for x in supportedSignals]
00153 
00154         for sig in supportedSignals:
00155             if hasattr(signal, 'SIGHUP') and sig == signal.SIGHUP:
00156                 signal.signal(sig, self._hupHandler)
00157             else:
00158                 signal.signal(sig, self._intHandler)

def MoinMoin.support.flup.server.threadedserver.ThreadedServer._intHandler (   self,
  signum,
  frame 
) [private]

Definition at line 143 of file threadedserver.py.

00143 
00144     def _intHandler(self, signum, frame):
00145         self._keepGoing = False

Override to provide access control.

Definition at line 133 of file threadedserver.py.

00133 
00134     def _isClientAllowed(self, addr):
00135         """Override to provide access control."""
00136         return True

Called with just about each iteration of the main loop. Meant to
be overridden.

Definition at line 117 of file threadedserver.py.

00117 
00118     def _mainloopPeriodic(self):
00119         """
00120         Called with just about each iteration of the main loop. Meant to
00121         be overridden.
00122         """
00123         pass

Definition at line 159 of file threadedserver.py.

00159 
00160     def _restoreSignalHandlers(self):
00161         for signum,handler in self._oldSIGs:
00162             signal.signal(signum, handler)

def MoinMoin.support.flup.server.threadedserver.ThreadedServer.run (   self,
  sock,
  timeout = 1.0 
)
The main loop. Pass a socket that is ready to accept() client
connections. Return value will be True or False indiciating whether
or not the loop was exited due to SIGHUP.

Definition at line 56 of file threadedserver.py.

00056 
00057     def run(self, sock, timeout=1.0):
00058         """
00059         The main loop. Pass a socket that is ready to accept() client
00060         connections. Return value will be True or False indiciating whether
00061         or not the loop was exited due to SIGHUP.
00062         """
00063         # Set up signal handlers.
00064         self._keepGoing = True
00065         self._hupReceived = False
00066 
00067         # Might need to revisit this?
00068         if not sys.platform.startswith('win'):
00069             self._installSignalHandlers()
00070 
00071         # Set close-on-exec
00072         setCloseOnExec(sock)
00073         
00074         # Main loop.
00075         while self._keepGoing:
00076             try:
00077                 r, w, e = select.select([sock], [], [], timeout)
00078             except select.error, e:
00079                 if e[0] == errno.EINTR:
00080                     continue
00081                 raise
00082 
00083             if r:
00084                 try:
00085                     clientSock, addr = sock.accept()
00086                 except socket.error, e:
00087                     if e[0] in (errno.EINTR, errno.EAGAIN):
00088                         continue
00089                     raise
00090 
00091                 setCloseOnExec(clientSock)
00092                 
00093                 if not self._isClientAllowed(addr):
00094                     clientSock.close()
00095                     continue
00096 
00097                 # Hand off to Connection.
00098                 conn = self._jobClass(clientSock, addr, *self._jobArgs)
00099                 if not self._threadPool.addJob(conn, allowQueuing=False):
00100                     # No thread left, immediately close the socket to hopefully
00101                     # indicate to the web server that we're at our limit...
00102                     # and to prevent having too many opened (and useless)
00103                     # files.
00104                     clientSock.close()
00105 
00106             self._mainloopPeriodic()
00107 
00108         # Restore signal handlers.
00109         self._restoreSignalHandlers()
00110 
00111         # Return bool based on whether or not SIGHUP was received.
00112         return self._hupReceived
        
Wait for running threads to finish.

Definition at line 113 of file threadedserver.py.

00113 
00114     def shutdown(self):
00115         """Wait for running threads to finish."""
00116         self._threadPool.shutdown()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 64 of file threadedserver.py.

Definition at line 52 of file threadedserver.py.

Definition at line 51 of file threadedserver.py.

Definition at line 63 of file threadedserver.py.

Definition at line 151 of file threadedserver.py.

Definition at line 54 of file threadedserver.py.


The documentation for this class was generated from the following file: