Remove timeouts before running code. #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I wasn't sure why the run calls were waiting for 500ms before actually running, so I took the timeouts out to see what would happen. The only think I noticed was a race condition between the exec cells and the onload macro. But the exec cells are already designed to retry if things aren't ready for them, so I just added a check that the onload has loaded as well.
Since we don't have this wait before the run function actually runs, I moved the pyodide_running flag handling inside the runPython function. Thus, this function is responsible for all the state setting; everyone else just checks it. I'm a little worried that there could be a TOCTOU bug here, if we get interrupted between the check and the function call. I don't know enough about JS concurrency to know if this is a worry or not. But it seems like a small danger, and I think it already existed in the code.
I realize I'm violating Chesterton's fence here, since I don't know that the code was supposed to do. My guesses are: