View Single Post
Old 04-18-2022, 10:53 AM   #2710
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by davidfor View Post
Looking at the code, I agree that the loop over the futures should be inside the with. But, I'm not sure what that would help.
The threading code is not easy to understand!

That said, when the ThreadPoolExecutor instance is garbage collected, which can happen any time after the "with" exits, some of the internal structure for the pool goes away. This is detected by the threads using weakrefs. It seems that in this case a thread can terminate instead of doing the next task on the queue. If this is true, and if there are more tasks than threads (more files than threads), then sometimes a task will be skipped. Putting the future.result() calls inside the "with" avoids this possibility.

I won't stake my reputation on this analysis.
chaley is offline   Reply With Quote