Deploying inside a process manager: must account for inherited socket family and type
See original GitHub issueHi,
I get an error when trying to run uvicorn with Circus, but only if using a socket with file descriptor (which I’d like to do to increase the number of processes).
circus.ini:
[socket:web]
host = 0.0.0.0
port = 80
[watcher:uvicorn]
cmd = uvicorn
# args = --host 0.0.0.0 --port 80 satemo.asgi:application
# --> works ok
args = --fd $(circus.sockets.web) satemo.asgi:application
# --> Fails
use_sockets = True
numprocesses = 1
Error:
File "c:\nss\venv\channels2\lib\site-packages\uvicorn\main.py", line 247, in startup
sock = socket.fromfd(config.fd, socket.AF_UNIX, socket.SOCK_STREAM)
UnboundLocalError: local variable 'socket' referenced before assignment
Environment:
- Windows 10
- Python 3.6.5
- uvicorn 0.4.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top Results From Across the Web
- socket()
This selects the protocol family that should be used. These families are defined in <sys/socket.h>. type: The type of socket you want to ......
Read more >systemd.exec - Freedesktop.org
Unit configuration files for services, sockets, mount points, and swap devices share a subset of configuration options which define the execution environment of ......
Read more >IBM Business Process Manager V8.0 Production Topologies
deployment manager is a specific type of IBM WebSphere Application Server whose primary task is the management and configuration of the cell in...
Read more >WSASocketA function (winsock2.h) - Win32 apps
The WSASocket function creates a socket that is bound to a specific transport-service provider. (ANSI)
Read more >Move 4.6 - Move User Guide - Nutanix Support Portal
The Move components are used in the following ways during various types of migration: ... Note: To deploy the Move VM, you must...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, just bumping this issue to note that I get this error on macOS, running uvicorn under supervisord.
Interestingly, I tried adding “import socket” at the top of the file, as was done in https://github.com/encode/uvicorn/pull/296, but that did not solve the issue. What did work was adding “import socket” right after line 352:
According to the socket module documentation:
I’d suggest to require full strings (e.g. ‘AF_INET’) and then get the constant values with
getattr( socket, user_given_input )
. To avoid following up with the versions of Python, I would not bother checking the arguments, but just return the exceptions given bysocket
, either at thegetattr
orsocket.fromfd()
levels.