Python Forum
Cleanest Way to Cancel a ThreadPool
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cleanest Way to Cancel a ThreadPool
#1
I have a backup script that I run weekly. Each folder that gets copied is independent of the others, one folder doesn't have to wait on the previous folder to finish copying, to start copying.

In an effort to learn asyncio and I decided to modify my backup script with async and a threadpoolexecutor. The problem is when an exception is raised (for example, copying a file produced an error), I want all other tasks to stop, because the backup is no longer valid. A little bit of searching came up with results that don't quite work. A few SO pages warned against stopping a thread, and a few other stated, even if I call task.cancel(), doesn't mean it will get cancelled right way. Synchronously, if an error occurred, the program will crash, and I can investigate. Is a clean method to asynchronously copy a folder with the ability to cancel should an error be raised, possible?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Confirm / Cancel button in Python & Flask ladak 0 783 Mar-18-2023, 11:26 AM
Last Post: ladak
  Using 2D array with Threadpool WiPi 1 1,875 Jun-25-2020, 09:19 AM
Last Post: WiPi
  how to cancel scheduler module event nanok66 0 2,133 May-11-2020, 10:31 PM
Last Post: nanok66
  Problem: Once I cancel the process my program will start working! Hadad 0 1,643 Jul-24-2019, 04:09 PM
Last Post: Hadad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020