DiamondLightSource / httomo

High-throughput tomography pipeline
https://diamondlightsource.github.io/httomo/
BSD 3-Clause "New" or "Revised" License
4 stars 3 forks source link

Fix `StandardTomoLoader` not being garbage collected until program termination #266

Open yousefmoazzam opened 3 months ago

yousefmoazzam commented 3 months ago

StandardTomoLoader suffers the same issue detailed in #264: it won't be garbage collected until program termination due to a reference to a bound method being given to weakref.finalize() https://github.com/DiamondLightSource/httomo/blob/fcc94798384244b01c5dbef231cfe30e00adda70/httomo/loaders/standard_tomo_loader.py#L80

However, there is also another issue:

Hence, the loader object's reference count will never drop to 0 during pipeline execution, and will only get garbage collected upon program termination.

Therefore, even if the same fix for #264 is applied here to use weakref.WeakMethod, we still need to change things to somehow make the reference count of the loader object drop to 0 when we no longer need it, while still keeping a reference to the instance of Pipeline in TaskRunner.