Python Forum
Launch another python command without waiting for a return. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Launch another python command without waiting for a return. (/thread-27644.html)

Pages: 1 2


RE: Launch another python command without waiting for a return. - SpongeB0B - Jun-18-2020

(Jun-18-2020, 07:03 AM)Gribouillis Wrote: There are 9 simple examples like this one on the pymotw3 page I linked above...
True I will dig it again.

But I don't understand in his example Scheduling Individual Tasks he use

from concurrent import futures AND import threading AND import time
Why using both module ? concurrent & Threading ?

(Jun-18-2020, 07:10 AM)Gribouillis Wrote: I think it should be
future = executor.submit(talk, 'This will be, a long text for testing purpose.')
You don't call the function. Just pass the function and its arguments to submit.
[Image: giphy.gif]

It worked ! Thank you @Gribouillis Thumbs Up


RE: Launch another python command without waiting for a return. - Gribouillis - Jun-18-2020

SpongeB0B Wrote:Why using both module ? concurrent & Threading ?
He uses threading because he wants to print the name of the current thread.
print(threading.current_thread().name)



RE: Launch another python command without waiting for a return. - DeaD_EyE - Jun-18-2020

You're calling the function talk directly and the return value of talk is called by executor, but the returned str is not callable. The executor needs to call the function. The name of a function is the reference to the function object living in memory. You can use also function as arguments.

This will fix your code.
future = executor.submit(talk, 'This will be, a long text for testing purpose.')
Function signature of Executor.submit
Function signature of threading.Thread


Very simplified the executor.submit looks like this:
def submit(function, *args, **kwargs):
    return fuction(*args, **kwargs)
The function submit calls the supplied function with arguments and keyword arguments.


RE: Launch another python command without waiting for a return. - Yoriz - Jun-18-2020

Note that
from concurrent.futures import ThreadPoolExecutor
is built on top of threading