add debug to aiohttp

This commit is contained in:
Thomas Farstrike
2025-05-20 11:48:20 +02:00
parent 3038eebfa2
commit c923ad3032
6 changed files with 26 additions and 14 deletions
Binary file not shown.
Binary file not shown.
+7 -2
View File
@@ -11,8 +11,13 @@ class Thread:
def start(self): def start(self):
# In MicroPython, _thread.start_new_thread doesn't support daemon threads directly # In MicroPython, _thread.start_new_thread doesn't support daemon threads directly
# We store the daemon attribute for compatibility, but it may not affect termination # We store the daemon attribute for compatibility, but it may not affect termination
#_thread.stack_size(32*1024) # 18KB or more causes "can't create thread" when starting relay.queue_worker thread
_thread.stack_size(12*1024) # 16KB still too much
# _thread.stack_size(32*1024)
#_thread.stack_size(10*1024) # might not be enough
stacksize = 12*1024
print(f"starting thread with stacksize {stacksize}")
_thread.stack_size(stacksize)
_thread.start_new_thread(self.run, ()) _thread.start_new_thread(self.run, ())
def run(self): def run(self):
+9 -8
View File
@@ -40,9 +40,9 @@ def _run_callback(callback, *args):
"""Add callback to queue for execution.""" """Add callback to queue for execution."""
try: try:
_callback_queue.append((callback, args)) _callback_queue.append((callback, args))
_log_debug(f"Queued callback {callback}, args={args}, queue size: {len(_callback_queue)}") #_log_debug(f"Queued callback {callback}, args={args}, queue size: {len(_callback_queue)}")
except IndexError: except IndexError:
_log_error("Callback queue full, dropping callback") _log_error("ERROR: websocket.py callback queue full, dropping callback")
async def _process_callbacks_async(): async def _process_callbacks_async():
"""Process queued callbacks asynchronously.""" """Process queued callbacks asynchronously."""
@@ -52,9 +52,9 @@ async def _process_callbacks_async():
try: try:
callback, args = _callback_queue.popleft() callback, args = _callback_queue.popleft()
if callback is not None: if callback is not None:
_log_debug(f"Executing callback {callback} with {len(args)} args") #_log_debug(f"Executing callback {callback} with {len(args)} args")
for i, arg in enumerate(args): #for i, arg in enumerate(args):
_log_debug(f"Arg {i}: {arg}") # _log_debug(f"Arg {i}: {arg}")
try: try:
callback(*args) callback(*args)
except Exception as e: except Exception as e:
@@ -155,7 +155,7 @@ class WebSocketApp:
"""Start ping task.""" """Start ping task."""
if self.ping_interval: if self.ping_interval:
_log_debug(f"NOT Starting ping task with interval {self.ping_interval}s") _log_debug(f"NOT Starting ping task with interval {self.ping_interval}s")
#asyncio.create_task(self._send_ping_async()) asyncio.create_task(self._send_ping_async())
def _stop_ping_thread(self): def _stop_ping_thread(self):
"""No-op, ping handled in async task.""" """No-op, ping handled in async task."""
@@ -167,6 +167,7 @@ class WebSocketApp:
self.last_ping_tm = time.time() self.last_ping_tm = time.time()
try: try:
if self.ws and not self.ws.ws.closed: if self.ws and not self.ws.ws.closed:
self.ping_payload = "ping"
_log_debug(f"Sending ping with payload: {self.ping_payload}") _log_debug(f"Sending ping with payload: {self.ping_payload}")
await self.ws.send_bytes(self.ping_payload.encode() if isinstance(self.ping_payload, str) else self.ping_payload) await self.ws.send_bytes(self.ping_payload.encode() if isinstance(self.ping_payload, str) else self.ping_payload)
else: else:
@@ -293,10 +294,10 @@ class WebSocketApp:
self.ws = ws self.ws = ws
_log_debug("WebSocket connected, running on_open callback") _log_debug("WebSocket connected, running on_open callback")
_run_callback(self.on_open, self) _run_callback(self.on_open, self)
self._start_ping_task() #self._start_ping_task() this ping task isn't part of the protocol, pings are sent by the server
async for msg in ws: async for msg in ws:
_log_debug(f"Received msg: type={msg.type}, data={str(msg.data)[:20]}...") _log_debug(f"websocket.py _connect_and_run received msg: type={msg.type}, length: {len(msg.data)} and data={str(msg.data)[:50]}...")
if not self.running: if not self.running:
_log_debug("Not running, breaking message loop") _log_debug("Not running, breaking message loop")
break break
@@ -10,9 +10,13 @@ from nostr.message_type import ClientMessageType
#filters = Filters([Filter(authors=[<a nostr pubkey in hex>], kinds=[EventKind.TEXT_NOTE])]) #filters = Filters([Filter(authors=[<a nostr pubkey in hex>], kinds=[EventKind.TEXT_NOTE])])
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[EventKind.TEXT_NOTE])]) #filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[EventKind.TEXT_NOTE])])
timestamp = round(time.time()-10) #timestamp = round(time.time()-50)
#timestamp = round(time.time()) # going for zero events to check memory use #timestamp = round(time.time()) # going for zero events to check memory use
#timestamp = round(time.time()-100)
# on esp32, it needs this correction:
#timestamp = time.time() + 946684800 - 1000
timestamp = round(time.time()-100)
#timestamp = round(time.time()-1000) #timestamp = round(time.time()-1000)
#timestamp = round(time.time()-5000) #timestamp = round(time.time()-5000)
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)]) #filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)])
@@ -36,9 +36,11 @@ def stress_test_thread():
wsapp.run_forever() wsapp.run_forever()
print("after run_forever") print("after run_forever")
_thread.stack_size(32*1024) _thread.stack_size(32*1024)
_thread.start_new_thread(stress_test_thread, ()) _thread.start_new_thread(stress_test_thread, ())
time.sleep(5) time.sleep(5)
print("sending it") print("sending it")
# nothing: # nothing: