Message227017
Bind method may easily fail on Unix if there is no permission to bind to a privileged port:
>>> try: TCPServer(("", 80), ...)
... except Exception as err: err
...
PermissionError(13, 'Permission denied')
>>> gc.collect()
__main__:1: ResourceWarning: unclosed <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>
0
This problem is inherited by HTTPServer and WSGIServer. My current workaround includes this code in a BaseServer fixup mixin, invoking server_close() if __init__() fails:
class Server(BaseServer, Context):
def __init__(self, ...):
try:
super().__init__((host, port), RequestHandlerClass)
except: # Workaround for socketserver.TCPServer leaking socket
self.close()
raise
def close(self):
return self.server_close() |
|
Date |
User |
Action |
Args |
2014-09-18 00:25:22 | martin.panter | set | recipients:
+ martin.panter |
2014-09-18 00:25:22 | martin.panter | set | messageid: <1410999922.66.0.432841070426.issue22435@psf.upfronthosting.co.za> |
2014-09-18 00:25:22 | martin.panter | link | issue22435 messages |
2014-09-18 00:25:20 | martin.panter | create | |
|