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

RuntimeError: cannot join current thread #51

Closed
garbb opened this issue Jun 10, 2017 · 5 comments
Closed

RuntimeError: cannot join current thread #51

garbb opened this issue Jun 10, 2017 · 5 comments
Labels

Comments

@garbb
Copy link

garbb commented Jun 10, 2017

Running python 2.7.13 on windows 7 x64.

Running the following code gets a random crash after anywhere between 12-16 hours later.

import GDAX

class myWebsocketClient(GDAX.WebsocketClient):
	def onOpen(self):
		self.url = "wss://ws-feed.gdax.com/"
		self.products = ["BTC-USD"]
	def onMessage(self, msg):
		if 'price' in msg and 'type' in msg and msg["type"] == 'match':
			print msg['time'], float(msg['price'])

			
wsClient = myWebsocketClient()
wsClient.start()

Crash

-- Socket Closed --
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build\bdist.win32\egg\GDAX\WebsocketClient.py", line 28, in _go
    self._listen()
  File "build\bdist.win32\egg\GDAX\WebsocketClient.py", line 57, in _listen
    self.close()
  File "build\bdist.win32\egg\GDAX\WebsocketClient.py", line 68, in close
    self.thread.join()
  File "C:\Python27\lib\threading.py", line 931, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
@garbb
Copy link
Author

garbb commented Jun 17, 2017

Well I at least have found an easy way to re-create this crash. Run the code I posted and then close the connection from python.exe with tcpview (this is for windows) and the crash occurs.

@garbb
Copy link
Author

garbb commented Jun 22, 2017

This exception can be avoided by removing "self.thread.join()" from line 68 of GDAX-0.3.1-py2.7.egg\GDAX\WebsocketClient.py.
Then when the connection drops, the .onClose() that you write when you create your websocketclient will be called so you can handle re-connecting or whetever you want.

Although I have no idea if this is the best solution or if it will cause other problems...

@danpaquin
Copy link
Owner

This line has been removed. We should consider options to add this back without the possibility of errors.

@royitaqi
Copy link

royitaqi commented Mar 14, 2018

Hi @danpaquin ,

How is this problem going? I tried to subscribe to "user" channel (authenticated) and the connection closed very soon. Retried many times and they all die after the same amount of time. Looked like it was a heartbeat problem. Below is my log output:

$ python gdax_user.py -a int
00:00:00,385  I  GdaxUser: opening
00:00:00,933  I  GdaxUser: received message: {'channels': [{'name': 'user', 'product_ids': ['ETH-USD']}], 'type': 'subscriptions'}
Connection is already closed. - data: None
00:01:00,473  C  GdaxUser: closing

Look at the timestamp, apparently the connection was closed from the server side at 1-minute mark.

I tried a similar piece of code but subscribe to "level2" and/or "ticker" channels and they seem to work fine. The problem appear to only happen when I'm subscribing to "user" channel.

@royitaqi
Copy link

royitaqi commented Mar 14, 2018

Let me create a new issue, since this one is closed and I'm not totally sure this one is exactly the same reason as this thread.

Created #276

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

3 participants