unicex 0.13.4__py3-none-any.whl → 0.13.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
unicex/_base/websocket.py CHANGED
@@ -95,12 +95,7 @@ class Websocket:
95
95
  async def stop(self) -> None:
96
96
  """Останавливает вебсокет и рабочие задачи."""
97
97
  self._running = False
98
- for task in self._tasks:
99
- task.cancel()
100
- self._tasks.clear()
101
-
102
- # Очистка очереди
103
- self._queue = asyncio.Queue()
98
+ await self._after_disconnect()
104
99
 
105
100
  async def restart(self) -> None:
106
101
  """Перезапускает вебсокет."""
@@ -184,11 +179,29 @@ class Websocket:
184
179
 
185
180
  async def _after_disconnect(self) -> None:
186
181
  """Вызывается после отключения от вебсокета."""
182
+ current_task = asyncio.current_task()
183
+
184
+ # Останавливаем воркеров, исключая задачу, которая уже выполняет остановку
185
+ tasks_to_wait: list[asyncio.Task] = []
187
186
  for task in self._tasks:
187
+ if task is current_task:
188
+ continue
189
+
188
190
  task.cancel()
191
+ tasks_to_wait.append(task)
192
+
193
+ # Дожидаемся завершения задач (в т.ч. воркеров)
194
+ if tasks_to_wait:
195
+ results = await asyncio.gather(*tasks_to_wait, return_exceptions=True)
196
+ for task_result in results:
197
+ if isinstance(task_result, asyncio.CancelledError):
198
+ continue
199
+ if isinstance(task_result, Exception):
200
+ self._logger.warning(f"Worker raised during shutdown: {task_result}")
201
+
189
202
  self._tasks.clear()
190
203
 
191
- # Очистить очередь
204
+ # Очистить очередь уже безопасно, после остановки воркеров
192
205
  self._queue = asyncio.Queue()
193
206
 
194
207
  async def _send_subscribe_messages(self, conn: ClientConnection) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unicex
3
- Version: 0.13.4
3
+ Version: 0.13.6
4
4
  Summary: Unified Crypto Exchange API
5
5
  Author-email: LoveBloodAndDiamonds <ayazshakirzyanov27@gmail.com>
6
6
  License: BSD 3-Clause License
@@ -11,7 +11,7 @@ unicex/_abc/uni_client.py,sha256=ZjxK8aqCGLUUYy1UQTM9EvWn1IXwMkH2Db8sZrs1e_I,137
11
11
  unicex/_abc/uni_websocket_manager.py,sha256=yYKypPkIe3rKfWBuTsS8rkwIPljpd1588CYDkeTOYqE,9905
12
12
  unicex/_base/__init__.py,sha256=0TmevATGnRB3qow6tkCR8dQKNZCWKeib6YQjNJ4a1b0,236
13
13
  unicex/_base/client.py,sha256=asIIQLZlRwwmUDvxveSv7aCvth54iiSRJdz19bxGorI,8904
14
- unicex/_base/websocket.py,sha256=QMUXpQemmL5I-mE2j6i5SUL_pu8ZxUcQWduSSZ8nppE,11768
14
+ unicex/_base/websocket.py,sha256=haSV3dSgkT352n8knpLm_iI4ZlUGWWKFCB3k5Ua2esU,12542
15
15
  unicex/binance/__init__.py,sha256=sDk4ZjakRdpFMaMSpOCfqjf6ZPfAS9tlrt4WlDHtDkw,932
16
16
  unicex/binance/adapter.py,sha256=JbUFyjnDAFtyuYYrh90YeOvQOZQ6faim0nWS6U0NxXw,8799
17
17
  unicex/binance/client.py,sha256=1qPx0uRT4prC6saLBQ55pXDWcWTCKhYEwVIysiihPgU,60984
@@ -86,8 +86,8 @@ unicex/okx/uni_client.py,sha256=E_Wod0JSGt1K6k1mAIWnOv350pELbv-nic7g1KgOuos,8694
86
86
  unicex/okx/uni_websocket_manager.py,sha256=b4f_QjA64DJmENQdIGb5IOVc7kvit7KMCdWeCmRbxGY,9326
87
87
  unicex/okx/user_websocket.py,sha256=8c9kpm-xVa729pW93OKUGLHaE9MY0uzEpjIgNIFRF80,126
88
88
  unicex/okx/websocket_manager.py,sha256=wROXTUDqKzOE-wDnCtXso_MC4SzfPuPols5aPg_Z3y4,26027
89
- unicex-0.13.4.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
90
- unicex-0.13.4.dist-info/METADATA,sha256=JJ9HinBsvn_N73vdORc00UshzpIHa0HWojl3ooMjO14,11752
91
- unicex-0.13.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
- unicex-0.13.4.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
93
- unicex-0.13.4.dist-info/RECORD,,
89
+ unicex-0.13.6.dist-info/licenses/LICENSE,sha256=lNNK4Vqak9cXm6qVJLhbqS7iR_BMj6k7fd7XQ6l1k54,1507
90
+ unicex-0.13.6.dist-info/METADATA,sha256=0ZJmTSp8QjP6ONVvrs7B-q9kITzIUPIZOwxJBwrP3EE,11752
91
+ unicex-0.13.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
92
+ unicex-0.13.6.dist-info/top_level.txt,sha256=_7rar-0OENIg4KRy6cgjWiebFYAJhjKEcMggAocGWG4,7
93
+ unicex-0.13.6.dist-info/RECORD,,