-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (27 loc) · 1.15 KB
/
main.py
File metadata and controls
34 lines (27 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
from concurrent.futures import ThreadPoolExecutor
from order_ticker import RegionTickerOrderbookProcessor
async def run_coin_websocket(
connection_class, consumer_type: str, is_ticker: bool
) -> None:
"""지정된 웹소켓 클라이언트 클래스와 심볼을 사용하여 비동기 함수 실행."""
websocket_client = connection_class(consumer_type, is_ticker)
await websocket_client.process_ticker()
async def coin_present_websocket(connection_class) -> None:
"""두 개의 코인 웹소켓을 동시에 실행."""
loop = asyncio.get_running_loop()
# 스레드 풀을 생성
with ThreadPoolExecutor(max_workers=2) as executor:
# run_in_executor 사용하여 비동기 작업 실행
loop.run_in_executor(
executor,
lambda: asyncio.run(
run_coin_websocket(connection_class, "orderbook", False)
),
)
loop.run_in_executor(
executor,
lambda: asyncio.run(run_coin_websocket(connection_class, "ticker", True)),
)
if __name__ == "__main__":
asyncio.run(coin_present_websocket(RegionTickerOrderbookProcessor))