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

Python Crashes at the end of websocket Implementation #29

Closed
yogamurthy opened this issue May 21, 2017 · 7 comments
Closed

Python Crashes at the end of websocket Implementation #29

yogamurthy opened this issue May 21, 2017 · 7 comments
Labels

Comments

@yogamurthy
Copy link

yogamurthy commented May 21, 2017

I have noticed that "python crashed. windows is collecting information" constantly in Windows environment.
The program perfectly finishes and says goodbye, then python crashes with exit code 255
same crash on both 2.7 and 3.6

I modified the code a bit to avoid tihs error,

def onMessage(self, msg):
    print("Message type:", msg)
    self.MessageCount += 1
    if(self.MessageCount >= 100):
    	exit()

The last 2 lines are added in my program and it solved the issue.

@danpaquin
Copy link
Owner

Hello @yogamurthy --

Thanks for letting us know. Would you please share with us the environment details as well as the fill script you are running? Thanks!

@yogamurthy
Copy link
Author

OS: Windows 7
Python: tried in both 2.7 and 3.6

The following is the complete script im using now

import GDAX, time
class myWebsocketClient(GDAX.WebsocketClient):
def onOpen(self):
self.url = "wss://ws-feed.gdax.com/"
self.products = ["LTC-USD"]
self.MessageCount = 0
print("Lets count the messages!")
def onMessage(self, msg):
print("Message type:", msg["type"], "\t@ %.3f" % float(msg["price"]))
self.MessageCount += 1
if(self.MessageCount >= 100):
exit()
def onClose(self):
print("-- Goodbye! --")

wsClient = myWebsocketClient()
wsClient.start()
print(wsClient.url, wsClient.products)
while (wsClient.MessageCount < 500):
print("\nMessageCount =", "%i \n" % wsClient.MessageCount)
time.sleep(1)

@danpaquin
Copy link
Owner

danpaquin commented May 23, 2017

Hi @yogamurthy - Firstly, I would like to state I did not encounter this issue on my current Python interpreters, but I will do my best to help you out given the information on hand.

Under initial inspection of your script, it seems as though you are missing the last line here:

wsClient.close()

...but you said it exits with the 'Goodbye!' message, so I'm going to assume you have this line. Additionally, it would be better practice to change the onMessage method to the code following. While it didn't change the behavior, it might be a better way to implement a fix to your issue. The message count & close logic was to show how you might share variables between threads so feel free to modify this to suit your needs.

self.MessageCount += 1
if self.MessageCount >= 100 and 'type' in msg:
     print("Message type:", msg)

Please let me know if you have any additional questions!

@jwlondon98
Copy link

I have been getting a similar issue on my mac

@danpaquin
Copy link
Owner

Hi @jwlondon98 thank you for sharing your issue! Hopefully we can get this cleared up ASAP. Did the fixes above work? Are you getting the same error? What version of the project are you running?

@pretzel729
Copy link

pretzel729 commented May 26, 2017

My scripts have also been crashing near the end of any implementations of WebsocketClient.
I had been receiving a segmentation fault (core dump) error.
It happened most of the time but not all of the time. So probably a multithreading issue.
I think sometimes it was possible for the websocket connection in WebsocketClient to be called (in the secondary thread) after the socket had already closed (in the main thread).

If we join to the second thread after self.stop = True,but before self.ws.close(), the websocket connection can't close while the secondary thread is running.

In def close(self) of WebsocketClient.py:
Old code:
def close(self):
...
self.onClose()
self.stop = True
# self.thread = None
self.ws.close()

Proposed code:
def close(self):
...
self.onClose()
self.stop = True
# self.thread = None
self.thread.join()
self.ws.close()

@danpaquin
Copy link
Owner

This has been implemented in the most recent update to PyPI

@yogamurthy I will be closing this out within the next week -- please let us know if you encounter the same error with these changes.

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

No branches or pull requests

4 participants