From c6aa98aeb6dc036ee5d6ea96d0d7b777878d42a5 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Tue, 20 May 2025 22:47:24 +0200 Subject: [PATCH] reduce CPU usage --- internal_filesystem/lib/websocket.py | 4 +++- internal_filesystem/lib/websocket_nostr_receive.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal_filesystem/lib/websocket.py b/internal_filesystem/lib/websocket.py index 4810d1aa..e056c8a8 100644 --- a/internal_filesystem/lib/websocket.py +++ b/internal_filesystem/lib/websocket.py @@ -46,7 +46,9 @@ def _run_callback(callback, *args): async def _process_callbacks_async(): """Process queued callbacks asynchronously.""" + import _thread while True: + print(f"thread {_thread.get_ident()}: _process_callbacks_async") while _callback_queue: _log_debug("Processing callbacks queue...") try: @@ -64,7 +66,7 @@ async def _process_callbacks_async(): except IndexError: _log_debug("Callback queue empty") break - await asyncio.sleep(0.01) # Yield to other tasks + await asyncio.sleep(0.5) # Yield to other tasks class WebSocketApp: def __init__( diff --git a/internal_filesystem/lib/websocket_nostr_receive.py b/internal_filesystem/lib/websocket_nostr_receive.py index 1cd9326d..342df3f6 100644 --- a/internal_filesystem/lib/websocket_nostr_receive.py +++ b/internal_filesystem/lib/websocket_nostr_receive.py @@ -63,7 +63,8 @@ def printevents(): print("checking pool....") try: event_msg = relay_manager.message_pool.get_event() - print(f"event_msg: pubkey: {event_msg.event.public_key} created_at {event_msg.event.created_at}") + #print(f"main code got event_msg: pubkey: {event_msg.event.public_key} created_at {event_msg.event.created_at}") + print(f"main code got event_msg: pubkey: {event_msg.event.public_key} created_at {event_msg.event.created_at} with content '{event_msg.event.content}' and kind {event_msg.event.kind} and tags {event_msg.event.tags}") except Exception as e: #print(f"pool.get_event() got error: {e}") pass