wotanii
wotanii

Reputation: 2836

How to stop an infinite loop safely in JupyterLab?

We are using jupyterLab for some long running operations (doing physic simulations in our case). The user should be able to stop these operations safely without killing the kernel.

Is there a clean ways to do this?

Are there maybe even best practices for this?


My cell looks something like this:

environment = gym.make()
running = True
while running:
    environment.step()
    running = ???
serialize(environment)

Notes

Upvotes: 1

Views: 3407

Answers (1)

sammy
sammy

Reputation: 867

According to https://stackoverflow.com/a/19040553/, IPython interrupts the kernel by sending a SIGINT. Shouldn't it be possible to catch and handle the signal programmatically, as described in How to stop an infinite loop safely in Python?.

Edit: This sounds helpful: graceful interrupt of while loop in ipython notebook

Upvotes: 1

Related Questions