improve exception handling

This commit is contained in:
Thomas Farstrike
2025-05-21 12:27:02 +02:00
parent 57814037d3
commit 4d9f5ab83f
3 changed files with 14 additions and 6 deletions
+5 -2
View File
@@ -42,10 +42,13 @@ def printevents():
relay_manager = RelayManager()
#relay_manager.add_relay("wss://nostr-pub.wellorder.net")
print("relaymanager adding")
relay_manager.add_relay("wss://relay.damus.io")
#relay_manager.add_relay("wss://relay.damus.io")
#time.sleep(1)
relay_manager.add_relay("wss://relay.primal.net")
time.sleep(1)
print("relaymanager subscribing")
relay_manager.add_subscription(subscription_id, filters)
time.sleep(1)
print("opening connections") # after this, CPU usage goes high and stays there
relay_manager.open_connections({"cert_reqs": ssl.CERT_NONE}) # NOTE: This disables ssl certificate verification
time.sleep(2) # allow the connections to open
@@ -82,7 +85,7 @@ def printevents():
# somehow, if I run this in a thread, I get: can't create thread" at File "/lib/nostr/relay_manager.py", line 48, in open_connections
# tried stack sizes from 18KB up to 32KB
# on unix/desktop, 24KB crashes, 26KB is fine
_thread.stack_size(26*1024)
_thread.stack_size(16*1024)
_thread.start_new_thread(printevents, ())
#printevents()
+1
View File
@@ -17,6 +17,7 @@ class Thread:
#_thread.stack_size(10*1024) # might not be enough
#stacksize = 12*1024
# small stack sizes 8KB gives segfault directly
# 22KB or less is too tight on desktop, 23KB and more is fine
stacksize = 24*1024
print(f"starting thread with stacksize {stacksize}")
_thread.stack_size(stacksize)
+8 -4
View File
@@ -230,9 +230,10 @@ class WebSocketApp:
self.close()
return False
except Exception as e:
_log_error(f"run_forever got general exception: {e}")
_log_error(f"run_forever's _loop.run_until_complete() got general exception: {e}")
self.has_errored = True
return True
self.running = False
#return True
_log_debug("run_forever completed")
return self.has_errored
@@ -250,8 +251,11 @@ class WebSocketApp:
_log_debug(f"Reconnect interval set to {reconnect}s")
# Start callback processing task
callback_task = asyncio.create_task(_process_callbacks_async())
_log_debug("Started callback processing task")
try:
callback_task = asyncio.create_task(_process_callbacks_async())
_log_debug("Started callback processing task")
except Exception as e:
print(f"websocket.py: create_ask(_process_callbacks_async()) had exception {e}")
while self.running:
_log_debug("Main loop iteration: self.running=True")