reduce CPU usage

This commit is contained in:
Thomas Farstrike
2025-05-20 22:47:24 +02:00
parent 80ef199451
commit c6aa98aeb6
2 changed files with 5 additions and 2 deletions
+3 -1
View File
@@ -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__(
@@ -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