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

ReactorNotRestartable #114

Open
k128 opened this issue Nov 12, 2021 · 5 comments
Open

ReactorNotRestartable #114

k128 opened this issue Nov 12, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@k128
Copy link

k128 commented Nov 12, 2021

Issue subject

When I run the example websocket code twice, I get an error.

Code to run

from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient

def message_handler(message):
    print(message)

ws_client = WebsocketClient()
ws_client.start()

# Combine selected streams
ws_client.instant_subscribe(
    stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'],
    callback=message_handler,
)

ws_client.stop()

ws_client = WebsocketClient()
ws_client.start()

Error Message

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\threading.py", line 954, in _bootstrap_inner
>>>     self.run()
  File "C:\Program Files\Python39\lib\site-packages\binance\websocket\binance_socket_manager.py", line 74, in run
    reactor.run(installSignalHandlers=False)
  File "C:\Program Files\Python39\lib\site-packages\twisted\internet\base.py", line 1422, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)
  File "C:\Program Files\Python39\lib\site-packages\twisted\internet\base.py", line 1404, in startRunning
    ReactorBase.startRunning(cast(ReactorBase, self))
  File "C:\Program Files\Python39\lib\site-packages\twisted\internet\base.py", line 843, in startRunning
    raise error.ReactorNotRestartable()
twisted.internet.error.ReactorNotRestartable

Environment

Provide any relevant information about your setup, such as:

  • Version of binance-connector-python: binance-connector==1.7.0
  • Python version: Python 3.9.2
  • Operating system: Windows 10
@aisling11 aisling11 added the reviewing reviewing the issue label Nov 15, 2021
@veckybin
Copy link

veckybin commented Nov 17, 2021

Seems like we cannot restart the websocket client. I gave time.sleep(100) between stopping the connection and making one again but still did not work.
Only way I can restart is by running the python code again from the start.

@aisling11 aisling11 added enhancement New feature or request and removed reviewing reviewing the issue labels Dec 3, 2021
@aisling11
Copy link
Contributor

When the websocket connection is closed, the reactor ( from twisted.internet) needs to be closed as well and once this happens it can’t be restarted again within the same process (reference), so there’s not much we can do here, however we’ll explore adding an unsubscribe method to stop receiving events from streams and then able to subscribe again without closing the webscoket connection itself.

@veckybin
Copy link

So where is the unsubscribe method?

@aisling11
Copy link
Contributor

@veckybin There's an internal ticket for it but without ETA for now.

@2pd
Copy link
Contributor

2pd commented Feb 21, 2023

Please consider the new v3 version which has the new websocket design.

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

No branches or pull requests

4 participants