[Python-ideas] Python3 Multitasking

Andrew Barnert abarnert at yahoo.com
Sun May 26 00:10:35 CEST 2013


> From: Devyn Collier Johnson <devyncjohnson at gmail.com>
>Sent: Saturday, May 25, 2013 6:49 AM


>It may benefit many programmers if Python3 code could be multithreaded as easy as BASH code. For example, in BASH, if I wish to multithread a command, I put an ampersand at the end of the line. Then, the BASH interpreter will execute that line while continuing the execution of the script instead of waiting to finish that command. For Python3, I have two ideas for how the Python3 multitasking syntax should look.
>
>Option 1: SOME_COMMAND &


& already has a meaning, as an operator. This would be confusing to both human readers and the parser.

>Option 2: multitask(SOME_COMMAND)


This one is fine—and you can do it trivially today:

    import multiprocessing
    jobs = []
    def multitask(command):
        jobs.append(multiprocessing.Process(command))

And you're done.

If you want to limit the number of running processes, or use a pool instead of a process per task, or use threads instead of processes, or name the jobs and store them in a dict, or whatever, you can change the multitask function.


More information about the Python-ideas mailing list