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

Calling WebSocketClient.terminate() results in AttributeError #131

Closed
inactivist opened this issue Apr 23, 2014 · 3 comments
Closed

Calling WebSocketClient.terminate() results in AttributeError #131

inactivist opened this issue Apr 23, 2014 · 3 comments

Comments

@inactivist
Copy link

I tried this on the master branch on github as well, same issue.

Trying to force close a websocket from the client side, and .terminate() seemed to be just what I'm looking for.

python 2.7.3; Ubuntu 12.04 AMD64

Exception in thread WebSocketClient:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/someuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/ws4py/websocket.py", line 430, in run
    self.terminate()
  File "/home/someuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/ws4py/websocket.py", line 334, in terminate
    s._cleanup()
AttributeError: 'NoneType' object has no attribute '_cleanup'

$ pip freeze
argparse==1.2.1
ws4py==0.3.4
wsgiref==0.1.2

This may well be due to the structure of my program, I'm still investigating. But it appears that ws4py is calling terminate() internally during cleanup even though I've already terminated the connection.

@inactivist inactivist changed the title Calling .terminate() results in AttributeError Calling WebSocketClient.terminate() results in AttributeError Apr 23, 2014
@Lawouach
Copy link
Owner

It depends on how you set your client up. Do you have a small runnable client snippet that demonstrates that behavior?

@Lawouach
Copy link
Owner

There has been quite a lot of changes internally and I've never reproduced this issue.

@awelkie
Copy link
Contributor

awelkie commented Apr 5, 2016

I'm getting the same exception. Here's a snippet that causes it:

from time import sleep
from ws4py.client.threadedclient import WebSocketClient

if __name__ == '__main__':
    sock = WebSocketClient('wss://echo.websocket.org')
    sock.connect()
    sock.close()
    sleep(0.2)
    sock.terminate()

In my real code I'm calling sock.close() and sock.terminate() in a class's __exit__ function. The exception only happens occasionally but putting the sleep in the above snippets makes it happen every time. This makes me think it's probably a race condition between the main thread and the threadedclient thread.

Is this the right way to close a socket? Or should I be calling only one of close and terminate?

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

No branches or pull requests

3 participants