Skip to content

Commit c923ad3

Browse files
add debug to aiohttp
1 parent 3038eeb commit c923ad3

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed
-3.6 KB
Binary file not shown.
-3.55 KB
Binary file not shown.

internal_filesystem/lib/threading.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, dae
1111
def start(self):
1212
# In MicroPython, _thread.start_new_thread doesn't support daemon threads directly
1313
# We store the daemon attribute for compatibility, but it may not affect termination
14-
#_thread.stack_size(32*1024)
15-
_thread.stack_size(12*1024)
14+
# 18KB or more causes "can't create thread" when starting relay.queue_worker thread
15+
# 16KB still too much
16+
# _thread.stack_size(32*1024)
17+
#_thread.stack_size(10*1024) # might not be enough
18+
stacksize = 12*1024
19+
print(f"starting thread with stacksize {stacksize}")
20+
_thread.stack_size(stacksize)
1621
_thread.start_new_thread(self.run, ())
1722

1823
def run(self):

internal_filesystem/lib/websocket.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def _run_callback(callback, *args):
4040
"""Add callback to queue for execution."""
4141
try:
4242
_callback_queue.append((callback, args))
43-
_log_debug(f"Queued callback {callback}, args={args}, queue size: {len(_callback_queue)}")
43+
#_log_debug(f"Queued callback {callback}, args={args}, queue size: {len(_callback_queue)}")
4444
except IndexError:
45-
_log_error("Callback queue full, dropping callback")
45+
_log_error("ERROR: websocket.py callback queue full, dropping callback")
4646

4747
async def _process_callbacks_async():
4848
"""Process queued callbacks asynchronously."""
@@ -52,9 +52,9 @@ async def _process_callbacks_async():
5252
try:
5353
callback, args = _callback_queue.popleft()
5454
if callback is not None:
55-
_log_debug(f"Executing callback {callback} with {len(args)} args")
56-
for i, arg in enumerate(args):
57-
_log_debug(f"Arg {i}: {arg}")
55+
#_log_debug(f"Executing callback {callback} with {len(args)} args")
56+
#for i, arg in enumerate(args):
57+
# _log_debug(f"Arg {i}: {arg}")
5858
try:
5959
callback(*args)
6060
except Exception as e:
@@ -155,7 +155,7 @@ def _start_ping_task(self):
155155
"""Start ping task."""
156156
if self.ping_interval:
157157
_log_debug(f"NOT Starting ping task with interval {self.ping_interval}s")
158-
#asyncio.create_task(self._send_ping_async())
158+
asyncio.create_task(self._send_ping_async())
159159

160160
def _stop_ping_thread(self):
161161
"""No-op, ping handled in async task."""
@@ -167,6 +167,7 @@ async def _send_ping_async(self):
167167
self.last_ping_tm = time.time()
168168
try:
169169
if self.ws and not self.ws.ws.closed:
170+
self.ping_payload = "ping"
170171
_log_debug(f"Sending ping with payload: {self.ping_payload}")
171172
await self.ws.send_bytes(self.ping_payload.encode() if isinstance(self.ping_payload, str) else self.ping_payload)
172173
else:
@@ -293,10 +294,10 @@ async def _connect_and_run(self):
293294
self.ws = ws
294295
_log_debug("WebSocket connected, running on_open callback")
295296
_run_callback(self.on_open, self)
296-
self._start_ping_task()
297+
#self._start_ping_task() this ping task isn't part of the protocol, pings are sent by the server
297298

298299
async for msg in ws:
299-
_log_debug(f"Received msg: type={msg.type}, data={str(msg.data)[:20]}...")
300+
_log_debug(f"websocket.py _connect_and_run received msg: type={msg.type}, length: {len(msg.data)} and data={str(msg.data)[:50]}...")
300301
if not self.running:
301302
_log_debug("Not running, breaking message loop")
302303
break

internal_filesystem/lib/websocket_nostr_receive.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010

1111
#filters = Filters([Filter(authors=[<a nostr pubkey in hex>], kinds=[EventKind.TEXT_NOTE])])
1212
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[EventKind.TEXT_NOTE])])
13-
timestamp = round(time.time()-10)
13+
#timestamp = round(time.time()-50)
1414
#timestamp = round(time.time()) # going for zero events to check memory use
15-
#timestamp = round(time.time()-100)
15+
16+
# on esp32, it needs this correction:
17+
#timestamp = time.time() + 946684800 - 1000
18+
19+
timestamp = round(time.time()-100)
1620
#timestamp = round(time.time()-1000)
1721
#timestamp = round(time.time()-5000)
1822
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)])

internal_filesystem/lib/websocket_raw_nostr_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def on_ping(wsapp, message):
1414

1515
def on_pong(wsapp, message):
1616
print("Got a pong! No need to respond")
17-
17+
1818

1919
def on_error(wsapp, message):
2020
print(f"Got error: {message}")
21-
21+
2222

2323
#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)
2424

@@ -36,9 +36,11 @@ def stress_test_thread():
3636
wsapp.run_forever()
3737
print("after run_forever")
3838

39+
3940
_thread.stack_size(32*1024)
4041
_thread.start_new_thread(stress_test_thread, ())
4142

43+
4244
time.sleep(5)
4345
print("sending it")
4446
# nothing:

0 commit comments

Comments
 (0)