nathanael-fijalkow commited on
Commit
d320f70
·
1 Parent(s): 429074d

avoid unmarshallable object errors

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -174,8 +174,28 @@ def evaluate_submission(file_obj, debug=False):
174
  print(f"EVALUATING: {file_path}")
175
  print(f"{'='*60}\n")
176
 
177
- spec = importlib.util.spec_from_file_location("student_module", file_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  student_module = importlib.util.module_from_spec(spec)
 
179
  spec.loader.exec_module(student_module)
180
 
181
  report = [f"## Results:\n"]
 
174
  print(f"EVALUATING: {file_path}")
175
  print(f"{'='*60}\n")
176
 
177
+ # Clear any cached bytecode to avoid unmarshallable object errors
178
+ import sys
179
+ import pathlib
180
+ if file_path in sys.modules:
181
+ del sys.modules[file_path]
182
+
183
+ # Remove .pyc files if they exist
184
+ py_file = pathlib.Path(file_path)
185
+ pycache_dir = py_file.parent / '__pycache__'
186
+ if pycache_dir.exists():
187
+ for pyc_file in pycache_dir.glob(f'{py_file.stem}*.pyc'):
188
+ try:
189
+ pyc_file.unlink()
190
+ except:
191
+ pass
192
+
193
+ # Import with a unique module name each time
194
+ import time
195
+ module_name = f"student_module_{int(time.time() * 1000000)}"
196
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
197
  student_module = importlib.util.module_from_spec(spec)
198
+ sys.modules[module_name] = student_module
199
  spec.loader.exec_module(student_module)
200
 
201
  report = [f"## Results:\n"]