Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows OSError: [WinError 10022] An invalid argument was supplie… #391

Closed
wants to merge 2 commits into from

Conversation

darindf
Copy link

@darindf darindf commented Jul 18, 2019

This solves the issue #342 of running multiple workers on Windows.

Specifically it avoid the sock.listen issue by closing the socket in the worker, and then letting asyncio.create_server reopen the socket using the same host, port and other configuration information from the inherited socket from the parent.

INFO: Started server process [36716]
INFO: Waiting for application startup.
Process Process-8:
Traceback (most recent call last):
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\multiprocessing\process.py", line 297, in _bootstrap
    self.run()
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\multiprocessing\process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\site-packages\uvicorn\main.py", line 307, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\site-packages\uvicorn\main.py", line 322, in serve
    await self.startup(sockets=sockets)
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\site-packages\uvicorn\main.py", line 349, in startup
    create_protocol, sock=sock, ssl=config.ssl
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\asyncio\base_events.py", line 1397, in create_server
    server._start_serving()
  File "c:\ProgramData\anaconda3\envs\py37.test\lib\asyncio\base_events.py", line 287, in _start_serving
    sock.listen(self._backlog)
OSError: [WinError 10022] An invalid argument was supplied
INFO: Started server process [41732]

server = await loop.create_server(
create_protocol, sock=sock, ssl=config.ssl
)
if os.name == 'nt':
Copy link
Member

@gvbgduh gvbgduh Sep 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be nt?
There's also a handy built-in lib - https://docs.python.org/3.7/library/platform.html#platform.system for that.
So, platform.system() == "Windows" might be a bit better choice.

@gvbgduh
Copy link
Member

gvbgduh commented Sep 19, 2019

There're also some failing tests, including against Windows.

Copy link
Member

@gvbgduh gvbgduh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some failing tests and a few comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants