Ensure all background commands are terminated before we close the connection.
This PR adds tracking of all outstanding BackgroundCommand inside ConnectionBase._current_bg_cmds. This attribute is changed from WeakSet() to set(), and the BackgroundCommand themselves deregister themselves when they terminate. This allows properly canceling all outstanding_ bg command when the connection is closed.
BackgroundCommand.init polls current bg cmds of its connection to reap any terminated commands, so that APIs that leak objects like the change introduced by this PR:
https://github.com/ARM-software/devlib/pull/624
or any other non-careful user does not result in endless leak of associated resources.
Ensure all background commands are terminated before we close the connection.
This PR adds tracking of all outstanding BackgroundCommand inside
ConnectionBase._current_bg_cmds
. This attribute is changed from WeakSet() to set(), and the BackgroundCommand themselves deregister themselves when they terminate. This allows properly canceling all outstanding_ bg command when the connection is closed.BackgroundCommand.init polls current bg cmds of its connection to reap any terminated commands, so that APIs that leak objects like the change introduced by this PR: https://github.com/ARM-software/devlib/pull/624 or any other non-careful user does not result in endless leak of associated resources.