Skip to content

Commit da3e2dd

Browse files
clear_asyncio_queue()
1 parent 24eef58 commit da3e2dd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1010
[How to upgrade to the latest version!](https://unicorn-binance-websocket-api.docs.lucit.tech/readme.html#installation-and-upgrade)
1111

1212
## 2.7.2.dev (development stage/unreleased/unstable)
13+
### Added
14+
- `clear_asyncio_queue()`
1315
### Changed
1416
- Made the logic of `is_exchange_type()` better readable.
1517
### Fixed

unicorn_binance_websocket_api/manager.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,14 +1435,37 @@ def add_total_received_bytes(self, size):
14351435
with self.total_received_bytes_lock:
14361436
self.total_received_bytes += int(size)
14371437

1438-
def clear_stream_buffer(self, stream_buffer_name=False):
1438+
def clear_asyncio_queue(self, stream_id: str = None) -> bool:
1439+
"""
1440+
Clear the asyncio queue of a specific stream.
1441+
1442+
:param stream_id: provide a stream_id
1443+
:type stream_id: str
1444+
1445+
:return: bool
1446+
"""
1447+
if stream_id is None:
1448+
logger.error(f"BinanceWebSocketApiManager.clear_asyncio_queue() - Missing parameter `stream_id`!")
1449+
return False
1450+
logger.debug(f"BinanceWebSocketApiManager.clear_asyncio_queue(stream_id={stream_id}) - Resetting asyncio_queue "
1451+
f"...")
1452+
try:
1453+
while True:
1454+
self.asyncio_queue[stream_id].get_nowait()
1455+
except asyncio.QueueEmpty:
1456+
logger.debug(
1457+
f"BinanceWebSocketApiManager.clear_asyncio_queue(stream_id={stream_id}) - Finished resetting of "
1458+
f"asyncio_queue!")
1459+
return True
1460+
1461+
def clear_stream_buffer(self, stream_buffer_name: Union[Literal[False], str] = False):
14391462
"""
14401463
Clear the
14411464
`stream_buffer <https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/wiki/%60stream_buffer%60>`__
14421465
14431466
:param stream_buffer_name: `False` to read from generic stream_buffer, the stream_id if you used True in
14441467
create_stream() or the string name of a shared stream_buffer.
1445-
:type stream_buffer_name: bool or str
1468+
:type stream_buffer_name: False or str
14461469
:return: bool
14471470
"""
14481471
if stream_buffer_name is False:

0 commit comments

Comments
 (0)