2

I recieved this code of which I would like to run the script runCortexReader.py on my windows 8.1 operating system. Spyder gives me this error :

AttributeError: 'module' object has no attribute 'SO_REUSEPORT'

The very same code works with Spyder on the same computer using Ubuntu 14.04 (using dual boot, not a virtual machine)

The problem is, that I really would like to run the script on Windows since it should later communicate with Matlab which is not installed on Ubuntu.

I'm using Python 2.7 on both systems.

Does anybody have an idea where the error could be?

xaverbandi
  • 33
  • 7

1 Answers1

3

SO_REUSEPORT (and also SO_REUSEADDR) is a socket related setting. In [SO]: How do SO_REUSEADDR and SO_REUSEPORT differ?, there's a good explanation for the differences between them.

SO_REUSEPORT is only present in newer Linux versions - defined in /usr/include/asm-generic/socket.h to a value of 15 typically (#define SO_REUSEPORT 15):

  • Is defined in Ubuntu 14, but not in Ubuntu 12 (the line is commented out: /* To add :#define SO_REUSEPORT 15 */)
  • Is defined in RHEL 7, but not in RHEL 5 (same comment)

On Win on the other hand, there's no such macro defined in Visual Studio's include files (typically Winsock2.h).

Also, [MS.Docs]: setsockopt function doesn't mention it in the possible option names.

What you'll have to do in order to get it working on Win (although it's not a nice approach), is to comment out (by adding a # char at the beginning) all the lines that reference it (I found it on the following file, but it might be present in other ones):

  • CortexDecoder.py line 244:

    self.cortexSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
    

or (this is even dirtier) in the same file(s), after importing the socket module, add this line:

socket.SO_REUSEPORT = socket.SO_REUSEADDR
CristiFati
  • 38,250
  • 9
  • 50
  • 87