diff --git a/internal_filesystem/lib/aiohttp/__init__.mpy b/internal_filesystem/lib/aiohttp/__init__.mpy deleted file mode 100644 index 524ce853..00000000 Binary files a/internal_filesystem/lib/aiohttp/__init__.mpy and /dev/null differ diff --git a/internal_filesystem/lib/aiohttp/aiohttp_ws.mpy b/internal_filesystem/lib/aiohttp/aiohttp_ws.mpy deleted file mode 100644 index 37f3b61d..00000000 Binary files a/internal_filesystem/lib/aiohttp/aiohttp_ws.mpy and /dev/null differ diff --git a/internal_filesystem/lib/threading.py b/internal_filesystem/lib/threading.py index 2627f96b..3b06d5a5 100644 --- a/internal_filesystem/lib/threading.py +++ b/internal_filesystem/lib/threading.py @@ -11,8 +11,13 @@ class Thread: def start(self): # 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 - #_thread.stack_size(32*1024) - _thread.stack_size(12*1024) + # 18KB or more causes "can't create thread" when starting relay.queue_worker thread + # 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, ()) def run(self): diff --git a/internal_filesystem/lib/websocket.py b/internal_filesystem/lib/websocket.py index 5c452b0f..53e7394d 100644 --- a/internal_filesystem/lib/websocket.py +++ b/internal_filesystem/lib/websocket.py @@ -40,9 +40,9 @@ def _run_callback(callback, *args): """Add callback to queue for execution.""" try: _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: - _log_error("Callback queue full, dropping callback") + _log_error("ERROR: websocket.py callback queue full, dropping callback") async def _process_callbacks_async(): """Process queued callbacks asynchronously.""" @@ -52,9 +52,9 @@ async def _process_callbacks_async(): try: callback, args = _callback_queue.popleft() if callback is not None: - _log_debug(f"Executing callback {callback} with {len(args)} args") - for i, arg in enumerate(args): - _log_debug(f"Arg {i}: {arg}") + #_log_debug(f"Executing callback {callback} with {len(args)} args") + #for i, arg in enumerate(args): + # _log_debug(f"Arg {i}: {arg}") try: callback(*args) except Exception as e: @@ -155,7 +155,7 @@ class WebSocketApp: """Start ping task.""" if self.ping_interval: _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): """No-op, ping handled in async task.""" @@ -167,6 +167,7 @@ class WebSocketApp: self.last_ping_tm = time.time() try: if self.ws and not self.ws.ws.closed: + self.ping_payload = "ping" _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) else: @@ -293,10 +294,10 @@ class WebSocketApp: self.ws = ws _log_debug("WebSocket connected, running on_open callback") _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: - _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: _log_debug("Not running, breaking message loop") break diff --git a/internal_filesystem/lib/websocket_nostr_receive.py b/internal_filesystem/lib/websocket_nostr_receive.py index b25623fe..4aa22664 100644 --- a/internal_filesystem/lib/websocket_nostr_receive.py +++ b/internal_filesystem/lib/websocket_nostr_receive.py @@ -10,9 +10,13 @@ from nostr.message_type import ClientMessageType #filters = Filters([Filter(authors=[], 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()-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()-5000) #filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)]) diff --git a/internal_filesystem/lib/websocket_raw_nostr_test.py b/internal_filesystem/lib/websocket_raw_nostr_test.py index 334cbd1c..e7607077 100644 --- a/internal_filesystem/lib/websocket_raw_nostr_test.py +++ b/internal_filesystem/lib/websocket_raw_nostr_test.py @@ -14,11 +14,11 @@ def on_ping(wsapp, message): def on_pong(wsapp, message): print("Got a pong! No need to respond") - + def on_error(wsapp, message): print(f"Got error: {message}") - + #wsapp = websocket.WebSocketApp("wss://testnet.binance.vision/ws/btcusdt@trade", on_message=on_message, on_ping=on_ping, on_pong=on_pong, on_error=on_error) @@ -36,9 +36,11 @@ def stress_test_thread(): wsapp.run_forever() print("after run_forever") + _thread.stack_size(32*1024) _thread.start_new_thread(stress_test_thread, ()) + time.sleep(5) print("sending it") # nothing: