Skip to content

Commit 4d9f5ab

Browse files
improve exception handling
1 parent 5781403 commit 4d9f5ab

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

draft_code/websocket_nostr_receive.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ def printevents():
4242
relay_manager = RelayManager()
4343
#relay_manager.add_relay("wss://nostr-pub.wellorder.net")
4444
print("relaymanager adding")
45-
relay_manager.add_relay("wss://relay.damus.io")
45+
#relay_manager.add_relay("wss://relay.damus.io")
46+
#time.sleep(1)
4647
relay_manager.add_relay("wss://relay.primal.net")
48+
time.sleep(1)
4749
print("relaymanager subscribing")
4850
relay_manager.add_subscription(subscription_id, filters)
51+
time.sleep(1)
4952
print("opening connections") # after this, CPU usage goes high and stays there
5053
relay_manager.open_connections({"cert_reqs": ssl.CERT_NONE}) # NOTE: This disables ssl certificate verification
5154
time.sleep(2) # allow the connections to open
@@ -82,7 +85,7 @@ def printevents():
8285
# 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
8386
# tried stack sizes from 18KB up to 32KB
8487
# on unix/desktop, 24KB crashes, 26KB is fine
85-
_thread.stack_size(26*1024)
88+
_thread.stack_size(16*1024)
8689
_thread.start_new_thread(printevents, ())
8790
#printevents()
8891

internal_filesystem/lib/threading.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def start(self):
1717
#_thread.stack_size(10*1024) # might not be enough
1818
#stacksize = 12*1024
1919
# small stack sizes 8KB gives segfault directly
20+
# 22KB or less is too tight on desktop, 23KB and more is fine
2021
stacksize = 24*1024
2122
print(f"starting thread with stacksize {stacksize}")
2223
_thread.stack_size(stacksize)

internal_filesystem/lib/websocket.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ def run_forever(
230230
self.close()
231231
return False
232232
except Exception as e:
233-
_log_error(f"run_forever got general exception: {e}")
233+
_log_error(f"run_forever's _loop.run_until_complete() got general exception: {e}")
234234
self.has_errored = True
235-
return True
235+
self.running = False
236+
#return True
236237
_log_debug("run_forever completed")
237238
return self.has_errored
238239

@@ -250,8 +251,11 @@ async def _async_main(self):
250251
_log_debug(f"Reconnect interval set to {reconnect}s")
251252

252253
# Start callback processing task
253-
callback_task = asyncio.create_task(_process_callbacks_async())
254-
_log_debug("Started callback processing task")
254+
try:
255+
callback_task = asyncio.create_task(_process_callbacks_async())
256+
_log_debug("Started callback processing task")
257+
except Exception as e:
258+
print(f"websocket.py: create_ask(_process_callbacks_async()) had exception {e}")
255259

256260
while self.running:
257261
_log_debug("Main loop iteration: self.running=True")

0 commit comments

Comments
 (0)