ARM-software / devlib

Library for interaction with and instrumentation of remote devices.
Apache License 2.0
47 stars 78 forks source link

connection: Terminate background commands on close() #626

Closed douglas-raillard-arm closed 1 year ago

douglas-raillard-arm commented 1 year ago

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.

douglas-raillard-arm commented 1 year ago

Updated PR with fix for RuntimeError(Set changed size during iteration)