Skip to content

Commit

Permalink
fixed coroutine handling and stop catching general exception
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-zehentleitner committed Mar 12, 2022
1 parent a3d0545 commit 324f9fa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

[Discussions about unicorn-binance-websocket-api releases!](https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/discussions/categories/releases)

## 1.40.2.dev (development stage/unreleased/unstable)
## 1.40.3.dev (development stage/unreleased/unstable)

## 1.40.3
### Changed
- Not catching general eception anymore - we must catch the specific exceptions
### Fixed
- Catch KeyError before the general exception in sockets to give better feedback within the callback.
- Error in coroutine loop handling

## 1.40.2
### Changed
Expand Down
4 changes: 3 additions & 1 deletion example_process_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

class BinanceWebSocketApiProcessStreams(object):
@staticmethod
def process_stream_data(received_stream_data_json, exchange="binance.com", stream_buffer_name="False"):
def process_stream_data(received_stream_data_json, stream_buffer_name="False"):
#
# START HERE!
#
Expand All @@ -58,6 +58,8 @@ def process_stream_data(received_stream_data_json, exchange="binance.com", strea
# to see the difference.
# Github: https://github.com/LUCIT-Systems-and-Development/unicorn-fy
# PyPI: https://pypi.org/project/unicorn-fy/
exchange = "binance.com"

if exchange == "binance.com" or exchange == "binance.com-testnet":
unicorn_fied_stream_data = UnicornFy.binance_com_websocket(received_stream_data_json)
elif exchange == "binance.com-futures" or exchange == "binance.com-futures-testnet":
Expand Down
2 changes: 1 addition & 1 deletion sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '1.40.2'
release = '1.40.3'

html_last_updated_fmt = "%b %d %Y at %H:%M (CET)"

Expand Down
4 changes: 2 additions & 2 deletions unicorn_binance_websocket_api/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(self,
high_performance=False):
threading.Thread.__init__(self)
self.name = "unicorn-binance-websocket-api"
self.version = "1.40.2.dev"
self.version = "1.40.3.dev"
logger.info(f"New instance of {self.get_user_agent()} on "
f"{str(platform.system())} {str(platform.release())} for exchange {exchange} started ...")
if disable_colorama is not True:
Expand Down Expand Up @@ -520,7 +520,7 @@ def _create_stream_thread(self,
asyncio.set_event_loop(loop)
socket = BinanceWebSocketApiSocket(self, stream_id, channels, markets)
try:
asyncio.ensure_future(socket.start_socket())
loop.create_task(socket.start_socket())
loop.run_forever()
except RuntimeError as error_msg:
if "cannot schedule new futures after interpreter shutdown" in str(error_msg):
Expand Down
14 changes: 7 additions & 7 deletions unicorn_binance_websocket_api/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ async def start_socket(self):
logger.error("BinanceWebSocketApiSocket.start_socket(" + str(self.stream_id) + ", " +
str(self.channels) + ", " + str(self.markets) + ") - KeyError (possibly within the"
"callback function) - error_msg: " + str(error_msg))
except Exception as error_msg:
logger.error("BinanceWebSocketApiSocket.start_socket(" + str(self.stream_id) + ", " +
str(self.channels) + ", " + str(self.markets) + ") - Exception General Exception "
" (possibly within the callback function) - error_msg: " + str(error_msg))
self.manager.stream_is_crashing(self.stream_id, str(error_msg))
self.manager.set_restart_request(self.stream_id)
sys.exit(1)
# except Exception as error_msg:
# logger.error("BinanceWebSocketApiSocket.start_socket(" + str(self.stream_id) + ", " +
# str(self.channels) + ", " + str(self.markets) + ") - Exception General Exception "
# " (possibly within the callback function) - error_msg: " + str(error_msg))
# self.manager.stream_is_crashing(self.stream_id, str(error_msg))
# self.manager.set_restart_request(self.stream_id)
# sys.exit(1)
except asyncio.TimeoutError as error_msg:
# Catching https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/issues/221
self.manager.stream_is_crashing(self.stream_id, error_msg)
Expand Down
5 changes: 2 additions & 3 deletions unittest_binance_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
import unittest
import os
import time
#import tracemalloc


#tracemalloc.start(25)
# import tracemalloc
# tracemalloc.start(25)

BINANCE_COM_API_KEY = ""
BINANCE_COM_API_SECRET = ""
Expand Down

0 comments on commit 324f9fa

Please sign in to comment.