Farama-Foundation / SuperSuit

A collection of wrappers for Gymnasium and PettingZoo environments (being merged into gymnasium.wrappers and pettingzoo.wrappers
Other
441 stars 56 forks source link

Fix subprocess envs not terminating on close #208

Closed callumcurtis closed 1 year ago

callumcurtis commented 1 year ago

Currently, ProcConcatVec's subprocesses are not being terminated when the environment is closed. Instead, they are only terminated when ProcConcatVec is garbage collected. This is a problem as the subprocesses cannot be explicitly terminated, and if the client accidentally holds on to a reference to ProcConcatVec, the child processes will never be terminated.

According to the Gymnasium documentation, the close method should be responsible for releasing all of the environment's resources.

This commit fixes the issue by terminating the subprocesses on close. The graceful shutdown period controls the number of seconds to wait for the subprocess environments to terminate before killing them. It is set to None by default, meaning that close will block until all subprocesses terminate on their own. The terminate instruction has been removed from the subprocess event loop as it is now redundant.

jjshoots commented 1 year ago

Hi, apologies for the late reply, but rebasing from master should fix tests.

elliottower commented 1 year ago

Closing in favor of updated code in #219, thanks for the contribution