programming:python:py-prefork-server
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programming:python:py-prefork-server [2015/01/03 05:46] – [Hooks] jay | programming:python:py-prefork-server [2023/11/10 20:06] (current) – [Donations] jay | ||
---|---|---|---|
Line 21: | Line 21: | ||
**NOTE:** The RPMs are **not** guaranteed to be the latest versions. | **NOTE:** The RPMs are **not** guaranteed to be the latest versions. | ||
- | {{: | + | {{: |
- | {{: | + | {{: |
- | ===== Donations ===== | + | |
- | By no means should anyone feel they //have// to donate. | + | |
- | < | ||
- | <form action=" | ||
- | <input type=" | ||
- | <input type=" | ||
- | <input type=" | ||
- | <img alt="" | ||
- | </ | ||
- | </ | ||
===== Issues and Feature Requests ===== | ===== Issues and Feature Requests ===== | ||
Please use the bug tracker built in to [[https:// | Please use the bug tracker built in to [[https:// | ||
Line 77: | Line 67: | ||
^ Name ^ Type ^ Description ^ | ^ Name ^ Type ^ Description ^ | ||
- | | self.proto | str | This will be either " | + | | self.protocol |
- | | self.reqsHandled | + | | self.requests_handled |
| self.conn | socket object or str | The socket object if this is a tcp server, otherwise this will be the actual payload of the udp packet | | | self.conn | socket object or str | The socket object if this is a tcp server, otherwise this will be the actual payload of the udp packet | | ||
- | | self.addr | tuple(str , int) | An address tuple containing (ip , port) | | + | | self.address |
| self.closed | boolean | A boolean, mainly for internal use, which says whether this child has been set to be closed | | | self.closed | boolean | A boolean, mainly for internal use, which says whether this child has been set to be closed | | ||
| self.error | str | A string error message, if set | | | self.error | str | A string error message, if set | | ||
Line 87: | Line 77: | ||
== 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. | 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. | ||
+ | |||
+ | == pre_bind(self) == | ||
+ | This hook is called before the main socket is created and bound to the ip: | ||
+ | |||
+ | == post_bind(self) == | ||
+ | As you might have guessed, this is called right after the '' | ||
== post_accept(self) == | == post_accept(self) == | ||
Line 102: | Line 98: | ||
Remember, if this is a udp server, self.conn will be a string with the actual packet payload. | Remember, if this is a udp server, self.conn will be a string with the actual packet payload. | ||
- | <source | + | <code python> |
def process_request(self): | def process_request(self): | ||
data = self.conn | data = self.conn | ||
self.resp_to(' | self.resp_to(' | ||
- | </source> | + | </code> |
== post_process_request(self) == | == post_process_request(self) == | ||
Line 123: | Line 119: | ||
=== The __init__ Signature === | === The __init__ Signature === | ||
<code python> | <code python> | ||
- | def __init__(self , childClass | + | def __init__(self , child_class |
- | | + | |
- | | + | |
+ | reuse_port=False): | ||
</ | </ | ||
Here is short description of each of those variables. | Here is short description of each of those variables. | ||
^ Name ^ Type ^ Description ^ | ^ Name ^ Type ^ Description ^ | ||
- | | childClass | + | | child_class |
- | | maxServers | + | | max_cervers |
- | | minServers | + | | min_servers |
- | | minSpareServers | + | | min_spare_servers |
- | | maxSpareServers | + | | max_spare_servers |
- | | maxRequests | + | | max_requests |
- | | bindIp | + | | bind_ip |
| port | int | The port number to bind to | | | port | int | The port number to bind to | | ||
- | | proto | str | The protocol to use (tcp or udp) | | + | | protocol |
| listen | int | TCP listen queue backlog | | | listen | int | TCP listen queue backlog | | ||
+ | | reuse_port | bool | If set, and available, SO_REUSEPORT will be used to bind the socket in the child | | ||
For anyone who has set up an Apache prefork server (or used Perl's '' | For anyone who has set up an Apache prefork server (or used Perl's '' | ||
Line 146: | Line 144: | ||
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: | + | This hook is called before the main socket is created and bound to the ip: |
- | == postBind(self) == | + | == post_bind(self) == |
- | As you might have guessed, this is called right after the '' | + | As you might have guessed, this is called right after the '' |
- | == 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. | This handles a SIGHUP. | ||
- | == intHandler(self , frame , num) == | + | == int_handler(self , frame , num) == |
This handles a SIGINT. | This handles a SIGINT. | ||
- | == termHandler(self , frame , num) == | + | == term_handler(self , frame , num) == |
By default, this does exactly the same thing as '' | By default, this does exactly the same thing as '' | ||
===== Example ===== | ===== Example ===== | ||
There is a full, working example in the distributions '' | There is a full, working example in the distributions '' |
programming/python/py-prefork-server.1420264006.txt.gz · Last modified: 2015/01/03 05:46 by jay