[Python-ideas] Add an introspection API to Executor
Andrew Barnert
abarnert at yahoo.com
Tue Aug 26 05:56:30 CEST 2014
On Monday, August 25, 2014 8:44 PM, Antoine Pitrou <antoine at python.org> wrote:
> > Le 25/08/2014 23:02, Ethan Furman a écrit :
>> On 08/25/2014 07:51 PM, Dan O'Reilly wrote:
>>>
>>> The IntrospectableQueue idea seems reasonable to me. I think I would
>>> prefer passing an introspectable (or similar)
>>> keyword to the Executor rather than a queue class, though.
>>
>> Passing the class is the better choice -- it means that future needs can
>> be more easily met by designing the queue variant needed and passing it
>> in -- having a keyword to select only one option is unnecessarily limiting.
>
> What if an implementation wants to use something other than a queue?
> It seems you're breaking the abstraction here.
A collection of threads and a shared queue is almost the definition of a thread pool. What else would you use?
Also, this could make it a lot easier to create variations on ThreadPoolExecutor without subclassing or forking it. For example, if you want your tasks to run in priority order, just give it a priority queue keyed on task.priority. If you want a scheduled executor, just give it a priority queue whose get method blocks until the first task's task.timestamp or a new task is added ahead of the first. And so on.
I'm not sure if that's a good idea or not, but it's an interesting possibility at least…
More information about the Python-ideas
mailing list