User Tools

Site Tools


programming:python:py-prefork-server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
programming:python:py-prefork-server [2015/01/03 05:50] – [The __init__ Signature] jayprogramming:python:py-prefork-server [2015/01/03 05:54] – [Hooks] jay
Line 87: Line 87:
 == initialize(self) == == initialize(self) ==
 Rather than reimplementing __init__, which you can do instead, you can just override this and setup variables and such that you need to set up.  This is the recommended approach.  Note that this is only called once, when the class is initialized.  This is **NOT** called on each new connection.  Use ''post_accept()'' for that purpose. Rather than reimplementing __init__, which you can do instead, you can just override this and setup variables and such that you need to set up.  This is the recommended approach.  Note that this is only called once, when the class is initialized.  This is **NOT** called on each new connection.  Use ''post_accept()'' for that purpose.
 +
 +== pre_bind(self) ==
 +This hook is called before the main socket is created and bound to the ip:port.  This is similar to the ''initialize()'' hook in the child class.  You can use this to set up global variables, etc.  Note that this will **only** be called if you are using reuse_port as the socket will be bound in the child process.
 +
 +== post_bind(self) ==
 +As you might have guessed, this is called right after the ''accept()'' socket has been created and bound.  Note that this will **only** be called if you are using reuse_port as the socket will be bound in the child process.
  
 == post_accept(self) == == post_accept(self) ==
Line 148: Line 154:
 Here they are with a brief description. Here they are with a brief description.
  
-== preBind(self) == +== pre_bind(self) == 
-This hook is called before the main socket is created and bound to the ip:port.  This is similar to the ''initialize()'' hook in the child class.  You can use this to set up global variables, etc.+This hook is called before the main socket is created and bound to the ip:port.  This is similar to the ''initialize()'' hook in the child class.  You can use this to set up global variables, etc.  Note that this will **not** be called if you are using reuse_port as the socket will be bound in the child process.
  
-== postBind(self) == +== post_bind(self) == 
-As you might have guessed, this is called right after the ''accept()'' socket has been created and bound.+As you might have guessed, this is called right after the ''accept()'' socket has been created and bound.  Note that this will **not** be called if you are using reuse_port as the socket will be bound in the child process.
  
-== preSignalSetup(self) ==+== pre_signal_setup(self) ==
 This is called before the signal handlers are set up This is called before the signal handlers are set up
  
-== postSignalSetup(self) ==+== post_signal_setup(self) ==
 This is called after the signal handlers have been set.  You can override the default signal handlers if you like.  More on that below. This is called after the signal handlers have been set.  You can override the default signal handlers if you like.  More on that below.
  
-== preInitChildren(self) ==+== pre_init_children(self) ==
 This is called before the child processes are initialized. This is called before the child processes are initialized.
  
-== postInitChildren(self) ==+== post_init_children(self) ==
 This is called after the child processes are initialized. This is called after the child processes are initialized.
  
-== preLoop(self) ==+== pre_loop(self) ==
 This is the last hook before the main server loop takes over. Any last minute setup items you wish to do should be done here. This is the last hook before the main server loop takes over. Any last minute setup items you wish to do should be done here.
  
-== preServerClose(self) ==+== pre_server_close(self) ==
 This is called before the server shuts down.  Any cleanup you wish to take care of before termination should be done here. This is called before the server shuts down.  Any cleanup you wish to take care of before termination should be done here.
  
-== hupHandler(self , frame , num) ==+== hup_handler(self , frame , num) ==
 This handles a SIGHUP.  If you have a config for your server, you could reload that here.  By default, this just ignores the signal. This handles a SIGHUP.  If you have a config for your server, you could reload that here.  By default, this just ignores the signal.
  
-== intHandler(self , frame , num) ==+== int_handler(self , frame , num) ==
 This handles a SIGINT.  The default is set an internal "stop" event to gracefully shutdown.  If you override this, call the ''super()'' so the graceful shutdown happens. This handles a SIGINT.  The default is set an internal "stop" event to gracefully shutdown.  If you override this, call the ''super()'' so the graceful shutdown happens.
  
-== termHandler(self , frame , num) ==+== term_handler(self , frame , num) ==
 By default, this does exactly the same thing as ''intHandler'' with a SIGTERM. By default, this does exactly the same thing as ''intHandler'' with a SIGTERM.
  
 ===== Example ===== ===== Example =====
 There is a full, working example in the distributions ''examples'' directory. There is a full, working example in the distributions ''examples'' directory.
programming/python/py-prefork-server.txt · Last modified: 2023/11/10 20:06 by jay