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

Clean exit of the Webots process when the (a specific) Supervisor's controller terminates #2858

Closed
mrshu opened this issue Mar 15, 2021 · 3 comments

Comments

@mrshu
Copy link

mrshu commented Mar 15, 2021

Is your feature request related to a problem? Please describe.

While playing with the RoboCupJunior Soccer Sim (essentially a few controllers + Webots; https://github.com/RoboCupJuniorTC/rcj-soccer-sim/), we ran more than a few times into a situation when the Supervisor ran into an exception and the whole simulation still continued, despite being in a state which was not really helpful. This was especially the case when trying to generate a video of the simulation -- we've lost quite some time that way.

Hence the request: being able to cleanly exit the Webots process when the Supervisr's controller terminates.

Describe the solution you'd like
A command-line flag which would make the Webots binary terminate as soon as the (a specific/any) Supervisor's controller terminates.

Alternatively, for the specific use case I have in mind it would be enough for the Webots binary to terminate whenever any controller terminates.

Describe alternatives you've considered
Since the code we're running in our particular use case is all in Python, we could potentially wrap everything in a large try/except block and then cleanly exit the Webots environment when we receive some exception. That opens a different can of worms though.


I am not sure how to go about implementing something like this but if you could give me some pointers, I'd be happy to give a PR a shot.

Thanks!

@omichel
Copy link
Member

omichel commented Mar 16, 2021

Why don't you use wb_supervisor_simulation_quit in your supervisor? That would fix the problem.

@omichel omichel closed this as completed Mar 16, 2021
@mrshu
Copy link
Author

mrshu commented Mar 16, 2021

Thanks for your suggestion @omichel!

Just to check that I understand it completely, since the controller is written in Python, you'd suggest we use something like atexit and call wb_supervisor_simulation_quit in its handler? I guess that would probably work and would not require any further updates to Webots.

Thanks again for all your help!

@omichel
Copy link
Member

omichel commented Mar 16, 2021

Yes, that's one possibility. Another one would be to call this function at the end of your Python program before quitting. If your program may fail for some reason, you should probably use try/catch constructs to call the Supervisor.quit() method in the catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants