figured out the threading on desktop/unix sortof

This commit is contained in:
Thomas Farstrike
2025-05-20 22:11:30 +02:00
parent 8375824ea8
commit 80ef199451
3 changed files with 15 additions and 16 deletions
+2 -6
View File
@@ -76,13 +76,9 @@ def execute_script_new_thread(scriptname, is_file, is_launcher, is_graphical):
print("Starting camera with extra stack size!")
stack=32*1024
else:
print("\n\n\nWHAAAAAAAAAAAAAAAAAA\n\n\n")
#stack=16*1024 # somehow, on desktop, this causes a segfault... but the code isn't executed even!!!
# [DEBUG 471155623] Connecting to wss://relay.damus.io
# [DEBUG 471155623] Using SSL with no certificate verification
stack=32*1024
stack=16*1024
_thread.stack_size(stack)
print(f"app.py set stack size to {stack}")
print(f"app.py set stack size for script to {stack}")
_thread.start_new_thread(execute_script, (scriptname, is_file, is_launcher, is_graphical))
except Exception as e:
print("main.py: execute_script_new_thread(): error starting new thread thread: ", e)
@@ -43,7 +43,8 @@ def printevents():
time.sleep(3)
#relay_manager.add_relay("wss://nostr-pub.wellorder.net")
print("relaymanager adding")
relay_manager.add_relay("wss://relay.damus.io")
#relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_relay("wss://relay.primal.net")
time.sleep(3)
print("relaymanager subscribing")
relay_manager.add_subscription(subscription_id, filters)
@@ -82,9 +83,10 @@ def printevents():
# 24KB is fine
# 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
# tried stack sizes from 18KB up to 32KB
#_thread.stack_size(16*1024)
#_thread.start_new_thread(printevents, ())
printevents()
# on unix/desktop, 24KB crashes, 26KB is fine
_thread.stack_size(26*1024)
_thread.start_new_thread(printevents, ())
#printevents()
#import gc
+7 -6
View File
@@ -15,17 +15,18 @@ except Exception as e:
from mpos import apps
apps.execute_script("builtin/system/button.py", True, False, False) # Install button handler through IRQ
def dummy():
pass
import sys
if sys.platform == "esp32":
apps.auto_connect()
else:
pass
#import _thread
#import time
# On unix/desktop, at least 24KB of stack size is needed in the REPL to make nostr work there
import _thread
_thread.stack_size(24*1024) # on unix/desktop, at least 24KB is needed for doing nostr connections from the REPL
_thread.start_new_thread(dummy, ()) # not just setting the stack_size but actually starting a thread to apply this globally
#_thread.stack_size(32*1024)
#time.sleep(1)
apps.auto_connect()
apps.restart_launcher()
# If we got this far without crashing, then no need to rollback the update: