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

cannot import name 'SO_REUSEPORT' #106

Closed
zzeric opened this Issue Jul 2, 2018 · 12 comments

Comments

Projects
None yet
8 participants
@zzeric
Copy link

zzeric commented Jul 2, 2018

File "/home/abc/anaconda3/lib/python3.6/site-packages/vibora/workers/handler.py", line 3, in
from socket import IPPROTO_TCP, TCP_NODELAY, SO_REUSEADDR, SOL_SOCKET, SO_REUSEPORT,socket
ImportError: cannot import name 'SO_REUSEPORT'

python version is 3.6.0, need to upgrade to 3.7?

@book987

This comment has been minimized.

Copy link

book987 commented Jul 2, 2018

work fine in 3.6.5

@rfyiamcool

This comment has been minimized.

Copy link

rfyiamcool commented Jul 2, 2018

use 3.6.x

@squeaky-pl

This comment has been minimized.

Copy link

squeaky-pl commented Jul 2, 2018

@frnkvieira

This depends on the kernel version of the machine that CPython was compiled on. I see the reporter is using anaconda which uses older kernel versions to ensure that the packages are forward compatible. I think Centos 5 is used there.

One of the ways to tackle this is to try to import it, then if it fails check the version of the kernel that you are currently using and hardcode the numerical values from the linux headers, so basically define them on the fly instead.

for example SO_REUSEPORT was introduced in Linux 3.9 (man 7 socket) and its values from the header files is 15, so if import fails you would get the kernel version and compare it again 3.9 and if it's 3.9 or newer you can just pass directly the integer value of it.

The numerical value doesnt change on Linux but of course it can be different on different operating systems but this problem is specific to Linux.

@frnkvieira

This comment has been minimized.

Copy link
Member

frnkvieira commented Jul 3, 2018

@squeaky-pl Priceless tip, many thanks! I'll add this ASAP.

@zzeric

This comment has been minimized.

Copy link
Author

zzeric commented Jul 3, 2018

@squeaky-pl thanks for reply. Yes,it's related to linux kernel and anaconda cpython compilation, it's strange about anaconda, my another centos kernel is 3.10, and the header file(/usr/include/asm-generic/socket.h) contains #define SO_REUSEPORT = 15, but anaconda python 3.6.4 still not support SO_REUSEPORT, maybe I need compile python myself.

@zzeric

This comment has been minimized.

Copy link
Author

zzeric commented Jul 3, 2018

I install python 3.7.0 without anaconda,it works. But "async" get to be a reserved keyword in 3.7, I need to modify somewhere myself, advise to rename the properties named as "async"
@frnkvieira

@frnkvieira

This comment has been minimized.

Copy link
Member

frnkvieira commented Jul 3, 2018

@zzeric this is already fixed in master branch, I'll do a release as soon as I fix the other pending issues

@kdebowski

This comment has been minimized.

Copy link

kdebowski commented Jul 10, 2018

SO_REUSEPORT does not exists on Windows (just like signal.pause). Windows supports SO_REUSEADDR.

ImportError: cannot import name 'SO_REUSEPORT' from 'socket' (C:\Python37\Lib\socket.py)

@danieldaeschle

This comment has been minimized.

Copy link
Contributor

danieldaeschle commented Jul 11, 2018

I have the same error on windows

@zzeric zzeric closed this Jul 12, 2018

@kdebowski

This comment has been minimized.

Copy link

kdebowski commented Jul 12, 2018

@zzeric why did you close this issue? It's not fixed yet. @frnkvieira 's answer was related to another problem.

@hexbee

This comment has been minimized.

Copy link

hexbee commented Jul 14, 2018

⚠️ Confirm that the issue is not fixed on current master branch.

  • Windows 10
  • Python 3.6.3 :: Anaconda, Inc.
  • vibora 0.0.7
  • Import Error :
Traceback (most recent call last):
  File "runapp.py", line 1, in <module>
    from vibora import Vibora, Request
  File "D:\Program_Files\Anaconda3\lib\site-packages\vibora-0.0.7-py3.6-win-amd64.egg\vibora\__init__.py", line 7, in <module>
    from .server import *
  File "D:\Program_Files\Anaconda3\lib\site-packages\vibora-0.0.7-py3.6-win-amd64.egg\vibora\server.py", line 10, in <module>
    from .workers.handler import RequestHandler
  File "D:\Program_Files\Anaconda3\lib\site-packages\vibora-0.0.7-py3.6-win-amd64.egg\vibora\workers\handler.py", line 3, in <module>
    from socket import IPPROTO_TCP, TCP_NODELAY, SO_REUSEADDR, SOL_SOCKET, SO_REUSEPORT, socket
ImportError: cannot import name 'SO_REUSEPORT'
@danieldaeschle

This comment has been minimized.

Copy link
Contributor

danieldaeschle commented Jul 17, 2018

According to https://stackoverflow.com/a/14388707/7301994 and https://stackoverflow.com/a/13638757/7301994 SO_REUSEADDR covers SO_REUSEPORT. We don't need SO_REUSEPORT at this point. I will create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment