sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.96k stars 2.19k forks source link

how to stop the ThreadedWebsocketManager running? #1256

Open some-crab opened 1 year ago

some-crab commented 1 year ago

Hi, I am using the ThreadedWebsocketManager example and I notice I can only use break key to stop it running. I guess this might not be a python-binance issue, but wondering how I can keyboard-interrupt the program. I tried:

if __name__ == "__main__":
    try:
            main()
        except KeyboardInterrupt:
            print('Got a keyboard interrupt')
            try:
                sys.exit(0)
            except SystemExit:
                os._exit(0)

and I also tried putting that into the handle_socket_message function, replacing main() with the message printing, but nothing. Is there a reasonable way to do this?

nguyenduclong1147 commented 9 months ago
stop_program =[False]
while not stop_program[0]:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        # socket.stop_socket(thread_name)
        socket.stop()
        stop_program[0] = True

This code may help you

richardsonbit commented 9 months ago

Sent from Proton Mail for iOS

El sáb, 8 oct, 2022 a las 05:31, some-crab @.***(mailto:El sáb, 8 oct, 2022 a las 05:31, some-crab < ha escrito:

Hi, I am using the ThreadedWebsocketManager example and I notice I can only use break key to stop it running. I guess this might not be a python-binance issue, but wondering how I can keyboard-interrupt the program. I tried:

if name == "main": try: main() except KeyboardInterrupt: print('Got a keyboard interrupt') try: sys.exit(0) except SystemExit: os._exit(0)

and I also tried putting that into the handle_socket_message function, replacing main() with the message printing, but nothing. Is there a reasonable way to do this?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>