Reset Network.run state after callback errors #1881
Rebased onto master and trimmed the description to the remaining stop/resume fix. The stop-and-resume tests (with and without profiling) and the NumPy suite pass.
Could you please comment on what this tests, in particular with the interrupt handler?
It checks that a failed run does not leave Network._globally_running set. The handler call is there for the user-visible side of that: if the flag stays True after a callback raises, a later Ctrl+C is treated as a stop request for a run that is not happening, and the KeyboardInterrupt is swallowed. So the test calls the handler with SIGINT after the failed run and expects the KeyboardInterrupt to come through, then checks both flags are cleared.
It already passes on current master (4 passed with the fix reverted), since the try/finally from #1752 does the cleanup. It only guards that. With the finally removed, all 4 cases fail with "DID NOT RAISE KeyboardInterrupt". It is unrelated to the multi-clock fix, so I can drop it from this PR if you would rather keep the diff to the stop/resume change.
Thanks for the explanation. Ok, this is mostly what I understood myself, I was only confused because I did not see a connection to the change about the clock time. But happy to leave this test in, it's a good safeguard.
mstimberg
Arthur031221
Stopping a simulation with multiple clocks can skip pending ticks on resume. When the stop time comes from a later clock, the next run advances the other clocks past their pending ticks.
The fix uses the earliest pending clock for the stop time. Tests cover stop and resume with and without profiling.
Tested with
.venv/bin/python -m pytest -q brian2/tests/test_network.py -k stop_with_multiple_clocks.Assisted by Claude/Codex.