You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #232 we used a Python atexit handler to cleanly shut down the ffmpeg process for video output. This was a good strategy to keep the code changes localized for that commit. However, the most Pythonic way to release resources is with context managers.
I know of one other place in Crazyswarm where we don't technically release resources correctly: we never close the file handle for the Joystick device in genericJoystick.py.
(I am not confident about ROS resources either. What happens if the script process receives SIGINT? I don't know.)
None of this has much impact because we normally only construct one Crazyswarm per process lifetime, with the exception of unit tests. Unit tests don't open the joystick. Normally they don't open ffmpeg either, but for the VideoWriter unit test we needed the hack of spawning a separate process to generate the video and run the atexit handler while the unit test process is still alive.
Making Crazyswarm a context manager won't break existing scripts unless I am missing something.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In #232 we used a Python
atexit
handler to cleanly shut down theffmpeg
process for video output. This was a good strategy to keep the code changes localized for that commit. However, the most Pythonic way to release resources is with context managers.I know of one other place in Crazyswarm where we don't technically release resources correctly: we never close the file handle for the Joystick device in
genericJoystick.py
.(I am not confident about ROS resources either. What happens if the script process receives
SIGINT
? I don't know.)None of this has much impact because we normally only construct one
Crazyswarm
per process lifetime, with the exception of unit tests. Unit tests don't open the joystick. Normally they don't openffmpeg
either, but for theVideoWriter
unit test we needed the hack of spawning a separate process to generate the video and run theatexit
handler while the unit test process is still alive.Making
Crazyswarm
a context manager won't break existing scripts unless I am missing something.Beta Was this translation helpful? Give feedback.
All reactions