[New-bugs-announce] [issue17956] add ScheduledExecutor

Charles-François Natali report at bugs.python.org
Sat May 11 19:45:42 CEST 2013

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list