Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to continue interrupted simulation runs #271

Open
fxjung opened this issue Sep 6, 2024 · 0 comments
Open

Allow to continue interrupted simulation runs #271

fxjung opened this issue Sep 6, 2024 · 0 comments
Labels
enhancement New feature or request extras

Comments

@fxjung
Copy link
Member

fxjung commented Sep 6, 2024

This makes sense for SimulationSet runs. The events are already serialized, the missing bit is dumping the current FleetState/Vehicle states/stoplists/current time/request generator state to disk before exiting. This should probably handle both keyboard interrupts and signals.

Example for keyboard interrupts:

import time

try:
    while True:
        time.sleep(1)
        print("doing something in a loop ...")
except KeyboardInterrupt:
    print('Exiting gracefully.... byebye')

Examples for signals:

import signal
import time

class GracefulKiller:
  kill_now = False
  def __init__(self):
    signal.signal(signal.SIGINT, self.exit_gracefully)
    signal.signal(signal.SIGTERM, self.exit_gracefully)
    signal.signal(signal.SIGQUIT, self.exit_gracefully)

  def exit_gracefully(self, signum, frame):
    self.kill_now = True

if __name__ == '__main__':
  killer = GracefulKiller()
  while not killer.kill_now:
    time.sleep(1)
    print("doing something in a loop ...")
   
  print("End of the program. I was killed gracefully :)")

(IPython sends KeyboardInterrupt on hitting the stop button.)

Crucially, it's likely not sufficient to just write pickles to disk. The exact step at which the simulation was interrupted needs to be found, discarding the incomplete step and storing the last state before the interruption. Also, a line in a file might be written partially, stoplists may not have been updated, etc.

@fxjung fxjung added enhancement New feature or request extras labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request extras
Projects
None yet
Development

No branches or pull requests

1 participant