mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-31 14:31:20 +00:00
handle huge polgon crypto message volume
This commit is contained in:
@@ -156,11 +156,10 @@ async def read_stdin():
|
||||
sys.stdin.flush()
|
||||
|
||||
if not line:
|
||||
break
|
||||
continue
|
||||
|
||||
if "qsize" in line:
|
||||
logger.info(f"PROVIDER INFO: Queue size: {queue.queue.qsize()}")
|
||||
|
||||
else:
|
||||
try:
|
||||
command = json.loads(line.strip())
|
||||
@@ -221,21 +220,20 @@ async def connect_and_stream():
|
||||
)
|
||||
tasks.add(handler_task)
|
||||
for i in range(0, 48):
|
||||
new_task = asyncio.create_task(
|
||||
queue.process_queue(lambda message: process_message(message))
|
||||
new_task = asyncio.shield(
|
||||
asyncio.create_task(
|
||||
queue.process_queue(lambda message: process_message(message))
|
||||
)
|
||||
)
|
||||
tasks.add(new_task)
|
||||
stdin_task = asyncio.create_task(read_stdin())
|
||||
stdin_task = asyncio.shield(asyncio.create_task(read_stdin()))
|
||||
try:
|
||||
connect_kwargs = CONNECT_KWARGS.copy()
|
||||
if "ping_timeout" not in connect_kwargs:
|
||||
connect_kwargs["ping_timeout"] = None
|
||||
if "close_timeout" not in connect_kwargs:
|
||||
connect_kwargs["close_timeout"] = None
|
||||
connect_kwargs["max_size"] = None
|
||||
connect_kwargs["read_limit"] = 2**32
|
||||
|
||||
try:
|
||||
async with websockets.connect(URL, **connect_kwargs) as websocket:
|
||||
|
||||
await login(websocket)
|
||||
response = await websocket.recv()
|
||||
messages = json.loads(response)
|
||||
@@ -312,7 +310,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
loop.set_exception_handler(lambda loop, context: None)
|
||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||
loop.add_signal_handler(sig, handle_termination_signal, logger)
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ if __name__ == "__main__":
|
||||
try:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
loop.set_exception_handler(lambda loop, context: None)
|
||||
loop.add_signal_handler(signal.SIGTERM, handle_termination_signal, logger)
|
||||
|
||||
asyncio.run_coroutine_threadsafe(
|
||||
@@ -298,7 +298,10 @@ if __name__ == "__main__":
|
||||
loop.run_forever()
|
||||
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
ERR = f"Unexpected error -> {e.__class__.__name__}: {e}"
|
||||
ERR = (
|
||||
f"PROVIDER ERROR: Unexpected error -> "
|
||||
f"{e.__class__.__name__ if hasattr(e, '__class__') else e}: {e}"
|
||||
)
|
||||
logger.error(ERR)
|
||||
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user