New submission from Charles-François Natali: Here's an implementation of a new ScheduledExecutor abstract class, with a concrete ScheduledThreadPoolExecutor implementation (see #995907). The aim is to provide a flexible, efficient and consistent framework for delayed and periodic tasks, leveraging on futures. Incidentally, this supersedes threading.Timer, which is quite fragile and inefficient.
Here's a patch with test (I didn't write the documentation, I prefer to have some feedback first :-), the API is complete. There's one thing that bothers me with the current implementation: when a future is cancelled, like for regular ThreadPoolExecutor, it doesn't get removed from the work queue right away, but only when it gets dequeued. For a delayed future, this means that one has to wait for the next scheduled execution (i.e. worst case <now> + future.period) for it to be effectively cancelled and removed from the queue, and for the executor to be shutdown. I'm considering using a callback (Future.add_done_callback()), that's kind of hackish but I don't see any other way. ---------- components: Library (Lib) files: scheduled-1.diff keywords: needs review, patch messages: 188935 nosy: neologix, pitrou, r.david.murray priority: normal severity: normal stage: patch review status: open title: add ScheduledExecutor type: enhancement Added file: http://bugs.python.org/file30221/scheduled-1.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17956> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com