This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socketserver.BaseRequestHandler inherited class
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: matsievskiysv
Priority: normal Keywords:

Created on 2021-11-16 16:21 by matsievskiysv, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg406413 - (view) Author: Sergey M. (matsievskiysv) Date: 2021-11-16 16:21
Due to 
```python
try:
    self.handle()
finally:
    self.finish()
```
construct in `socketserver.BaseRequestHandler.__init__()` method inherited classes with `overrided __init__()` method may suffer from incomplete initialization.
For example, in the following snippet
```python
def __init__(self, request, client_address, server):
    super().__init__(request, client_address, server)
    self.foo = 1
```
in some cases all the code after `super()` call will not be executed.

This is a MWE of the server with partially initialized Handler class
```python
from socketserver import UnixStreamServer, StreamRequestHandler, ForkingMixIn


class Handler(StreamRequestHandler):
    def __init__(self, request, client_address, server):
        super().__init__(request, client_address, server)
        self.foo = 1

    def handle(self):
        print(self.foo)


class ThreadedUnixStreamServer(ForkingMixIn, UnixStreamServer):
    pass


with ThreadedUnixStreamServer("/tmp/test.socket", Handler) as server:
    server.serve_forever()
```
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89976
2021-11-16 16:21:51matsievskiysvcreate