huajun07 / codesketcher

Visualise your code in action!
https://main.d1fr5et3wgts3j.amplifyapp.com/
MIT License
0 stars 0 forks source link

Fix/executor imports and cloning #67

Closed limanjun99 closed 1 year ago

limanjun99 commented 1 year ago

This PR fixes this cloning bug and this frame origin bug.

Fix for cloning bug

We compile the user's code first with a filename, then we only consider frames with frame.f_code.co_filename == our_filename. This removes the need for the hacky checking if in a import thing we did previously.

Fix for frame origin bug

We specify all raw variables with the prefix raw now (e.g. current_raw_local_variables). Then we only perform operations after we have converted them into our own format (that is JSON-friendly), so that they can be cloned.

Testing

Added testcase to the executor service. Also tested in frontend:

import threading
def worker():
    print('Worker thread')
threads = []
for _ in range(5):
    t = threading.Thread(target=worker)
    threads.append(t)
    t.start()
for t in threads:
    t.join()

Screenshot 2023-07-03 at 10 17 25 PM