Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
socketserver.ForkingMixIn Class Reference
Inheritance diagram for socketserver.ForkingMixIn:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def collect_children
def handle_timeout
def process_request

Static Public Attributes

int timeout = 300
 active_children = None
int max_children = 40

Detailed Description

Mix-in class to handle each request in a new process.

Definition at line 495 of file socketserver.py.


Member Function Documentation

Internal routine to wait for children that have exited.

Definition at line 503 of file socketserver.py.

00503 
00504     def collect_children(self):
00505         """Internal routine to wait for children that have exited."""
00506         if self.active_children is None: return
00507         while len(self.active_children) >= self.max_children:
00508             # XXX: This will wait for any child process, not just ones
00509             # spawned by this library. This could confuse other
00510             # libraries that expect to be able to wait for their own
00511             # children.
00512             try:
00513                 pid, status = os.waitpid(0, 0)
00514             except os.error:
00515                 pid = None
00516             if pid not in self.active_children: continue
00517             self.active_children.remove(pid)
00518 
00519         # XXX: This loop runs more system calls than it ought
00520         # to. There should be a way to put the active_children into a
00521         # process group and then use os.waitpid(-pgid) to wait for any
00522         # of that set, but I couldn't find a way to allocate pgids
00523         # that couldn't collide.
00524         for child in self.active_children:
00525             try:
00526                 pid, status = os.waitpid(child, os.WNOHANG)
00527             except os.error:
00528                 pid = None
00529             if not pid: continue
00530             try:
00531                 self.active_children.remove(pid)
00532             except ValueError as e:
00533                 raise ValueError('%s. x=%d and list=%r' % (e.message, pid,
00534                                                            self.active_children))

Here is the caller graph for this function:

Wait for zombies after self.timeout seconds of inactivity.

May be extended, do not override.

Definition at line 535 of file socketserver.py.

00535 
00536     def handle_timeout(self):
00537         """Wait for zombies after self.timeout seconds of inactivity.
00538 
00539         May be extended, do not override.
00540         """
00541         self.collect_children()

Here is the call graph for this function:

def socketserver.ForkingMixIn.process_request (   self,
  request,
  client_address 
)
Fork a new subprocess to process the request.

Definition at line 542 of file socketserver.py.

00542 
00543     def process_request(self, request, client_address):
00544         """Fork a new subprocess to process the request."""
00545         self.collect_children()
00546         pid = os.fork()
00547         if pid:
00548             # Parent process
00549             if self.active_children is None:
00550                 self.active_children = []
00551             self.active_children.append(pid)
00552             self.close_request(request)
00553         else:
00554             # Child process.
00555             # This must never return, hence os._exit()!
00556             try:
00557                 self.finish_request(request, client_address)
00558                 self.shutdown_request(request)
00559                 os._exit(0)
00560             except:
00561                 try:
00562                     self.handle_error(request, client_address)
00563                     self.shutdown_request(request)
00564                 finally:
00565                     os._exit(1)
00566 

Here is the call graph for this function:


Member Data Documentation

Definition at line 500 of file socketserver.py.

Definition at line 501 of file socketserver.py.

Definition at line 499 of file socketserver.py.


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