question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run uvicorn with multiple workers on Windows - WinError 87

See original GitHub issue

Describe the bug Uvicorn doesn’t seem to be able to start with multiple workers.

Code snippet Starlette Hello World

import uvicorn as uvicorn
from starlette.applications import Starlette
from starlette.responses import JSONResponse

app = Starlette(debug=True)


@app.route('/')
async def homepage(request):
    return JSONResponse({'hello': 'world'})


if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000, workers=2)

Expected behavior

Uvicorn starts and is ready to serve with multiple workers.

Environment

Windows 10 Uvicorn: 0.6.1 Python: 3.7.2 Starlette: 0.11.4

Additional context

(venv) C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37>python main.py

INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started parent process [35788]

Traceback (most recent call last):

  File "main.py", line 14, in <module>
    uvicorn.run(app, host='127.0.0.1', port=8000, workers=2)
	
  File "C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37\venv\lib\site-packages\uvicorn\main.py", line 274, in run
    supervisor.run(server.run, sockets=[socket])
	
  File "C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37\venv\lib\site-packages\uvicorn\supervisors\multiprocess.py", line 33, in run
    process.start()
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
	
AttributeError: Can't pickle local object 'request_response.<locals>.app'

(venv) C:\Users\marodev\source\repos\StarletteHelloWorldVirtualEnvPy37>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 99, in spawn_main
    new_handle = reduction.steal_handle(parent_pid, pipe_handle)
	
  File "C:\Users\marodev\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 82, in steal_handle
    _winapi.PROCESS_DUP_HANDLE, False, source_pid)
	
OSError: [WinError 87] The parameter is incorrect

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:38 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
Dementiycommented, Mar 18, 2022

The same issue with Python 3.9.10 and uvicorn 0.17.6.

1reaction
satish678commented, Jul 29, 2022

Upgrading Uvicorn to “0.18.1” solved for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deployment - Uvicorn
Run uvicorn --reload from the command line for local development. ... provides a lightweight way to run multiple worker processes, for example --workers...
Read more >
Python Worker - OSError: [WinError 87] The parameter is ...
Today I encountered the following error while using a Python worker on Windows: OSError: [WinError 87] The parameter is incorrect.
Read more >
python - OSError: [WinError 87]The parameter is incorrect
Here is the turorial code that run as a main process. task_master.py. import random, time, queue from multiprocessing.managers import ...
Read more >
https://raw.githubusercontent.com/encode/uvicorn/m...
WindowsSelectorEventLoopPolicy()` when using multiple workers to avoid "WinError 87" (#1454) 22/06/22 ## 0.17.6 - 2022-03-11 ### Changed - Change ...
Read more >
OSError: [WinError 87] The parameter is incorrect - Ortho4XP
Forgive me if someone else has posted about this issue but I can't seem to find it. When running the new Ortho4xp 1.30...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found