[Python-Dev] [PEP 3148] futures - execute computations asynchronously

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Mar 8 22:11:45 CET 2010


On 08:56 pm, digitalxero at gmail.com wrote:
>On Mon, Mar 8, 2010 at 12:04 PM, Dj Gilcrease <digitalxero at gmail.com> 
>wrote:
>>A style I have used in my own code in the past is a Singleton class
>>with register and create methods, where the register takes a
>>name(string) and the class and the create method takes the name and
>>*args, **kwargs and acts as a factory.
>
>
>So I decided to play with this design a little and since I made it a
>singleton I decided to place all the thread/process tracking and exit
>handle code in it instead of having the odd semi-global scoped
>_shutdown, _thread_references, _remove_dead_thread_references and
>_python_exit objects floating around in each executor file, seems to
>work well. The API would be
>
>from concurrent.futures import executors
>
>executor = executors.create(NAME, *args, **kwargs) # NAME is 'process'
>or 'thread' by default
>
>
>To create your own executor you create your executor class and add the
>following at the end

Getting rid of the process-global state like this simplifies testing 
(both testing of the executors themselves and of application code which 
uses them).  It also eliminates the unpleasant interpreter 
shutdown/module globals interactions that have plagued a number of 
stdlib systems that keep global state.

Jean-Paul


More information about the Python-Dev mailing list