Skip to content

Commit 72caf67

Browse files
API: restore sys.path after starting app
1 parent 518bb20 commit 72caf67

File tree

1 file changed

+5
-3
lines changed
  • internal_filesystem/lib/mpos

1 file changed

+5
-3
lines changed

internal_filesystem/lib/mpos/apps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
3737
}
3838
print(f"Thread {thread_id}: starting script")
3939
import sys
40-
path_before = sys.path
40+
path_before = sys.path[:] # Make a copy, not a reference
4141
if cwd:
4242
sys.path.append(cwd)
4343
try:
@@ -74,8 +74,10 @@ def execute_script(script_source, is_file, cwd=None, classname=None):
7474
tb = getattr(e, '__traceback__', None)
7575
traceback.print_exception(type(e), e, tb)
7676
return False
77-
print(f"Thread {thread_id}: script {compile_name} finished, restoring sys.path to {sys.path}")
78-
sys.path = path_before
77+
finally:
78+
# Always restore sys.path, even if we return early or raise an exception
79+
print(f"Thread {thread_id}: script {compile_name} finished, restoring sys.path from {sys.path} to {path_before}")
80+
sys.path = path_before
7981
return True
8082
except Exception as e:
8183
print(f"Thread {thread_id}: error:")

0 commit comments

Comments
 (0)