Skip to content

Commit 0c69fc6

Browse files
add stack size prints
1 parent 959e028 commit 0c69fc6

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

internal_filesystem/lib/aiohttp/aiohttp_ws.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ async def close(self):
191191
await self.send(b"", self.CLOSE)
192192

193193
async def _read_frame(self):
194+
import micropython
195+
print(f"aiohttp_ws.py thread stack used: {micropython.stack_use()}")
194196
header = await self.reader.read(2)
195197
if len(header) != 2: # pragma: no cover
196198
# raise OSError(32, "Websocket connection closed")
@@ -211,7 +213,9 @@ async def _read_frame(self):
211213
mask = await self.reader.read(4)
212214
print(f"mask is {mask}")
213215
payload = await self.reader.read(length)
214-
print(f"payload is {payload}")
216+
print(f"payload is {payload} with actual length {len(payload)}")
217+
if len(payload) != length:
218+
print("wrong payload length, this should be ignored!")
215219
if has_mask: # pragma: no cover
216220
payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
217221
return opcode, payload

internal_filesystem/lib/queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Queue:
77
def __init__(self, maxsize=0):
88
self._queue = []
99
self.maxsize = maxsize # 0 means unlimited
10+
#self.maxsize = 4 # limit to avoid stack overflow
1011
self._lock = _thread.allocate_lock() if _thread else None
1112

1213
def put(self, item):

internal_filesystem/lib/websocket.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ async def _connect_and_run(self):
297297
#self._start_ping_task() this ping task isn't part of the protocol, pings are sent by the server
298298

299299
async for msg in ws:
300+
import micropython
301+
print(f"websocket.py _connect_and_run thread stack used: {micropython.stack_use()}")
300302
_log_debug(f"websocket.py _connect_and_run received msg: type={msg.type}, length: {len(msg.data)} and data={str(msg.data)[:50]}...")
301303
if not self.running:
302304
_log_debug("Not running, breaking message loop")

internal_filesystem/lib/websocket_nostr_receive.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
#timestamp = round(time.time()-50)
1414
#timestamp = round(time.time()) # going for zero events to check memory use
1515

16-
# on esp32, it needs this correction:
17-
#timestamp = time.time() + 946684800 - 1000
16+
import sys
17+
if sys.platform == "esp32":
18+
# on esp32, it needs this correction:
19+
timestamp = time.time() + 946684800 - 1000
20+
else:
21+
timestamp = round(time.time()-1000)
22+
#timestamp = round(time.time()-1000)
23+
#timestamp = round(time.time()-5000)
1824

19-
timestamp = round(time.time()-100)
20-
#timestamp = round(time.time()-1000)
21-
#timestamp = round(time.time()-5000)
2225
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)])
2326
filters = Filters([Filter(kinds=[9735], since=timestamp)])
2427

@@ -31,6 +34,8 @@
3134
print(f"sending this: {message}")
3235

3336
def printevents():
37+
import micropython
38+
print(f"at the start, thread stack used: {micropython.stack_use()}")
3439
print("relaymanager")
3540
relay_manager = RelayManager()
3641
time.sleep(3)
@@ -43,21 +48,22 @@ def printevents():
4348
time.sleep(3) # allow the connections to open
4449
print("opening connections") # after this, CPU usage goes high and stays there
4550
relay_manager.open_connections({"cert_reqs": ssl.CERT_NONE}) # NOTE: This disables ssl certificate verification
46-
time.sleep(10) # allow the connections to open
51+
time.sleep(2) # allow the connections to open
4752
print("publishing:")
4853
relay_manager.publish_message(message)
49-
time.sleep(10) # allow the messages to send
54+
time.sleep(2) # allow the messages to send
5055
print("printing events:")
5156
#while relay_manager.message_pool.has_events():
52-
for _ in range(10):
57+
# allowing 30 seconds for stuff to come in...
58+
for _ in range(30):
5359
time.sleep(1)
5460
print(".")
5561
try:
5662
event_msg = relay_manager.message_pool.get_event()
57-
print(event_msg.event.content)
63+
print(f"event_msg: pubkey: {event_msg.event.public_key} created_at {event_msg.event.created_at}")
5864
except Exception as e:
5965
print(f"pool.get_event() got error: {e}")
60-
print("60 seconds passed, closing:")
66+
print("30 seconds passed, closing:")
6167
relay_manager.close_connections()
6268

6369
# new thread so REPL stays available

0 commit comments

Comments
 (0)