(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
.
It worked ! Thank you @
Gribouillis 
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)
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.
Note that
from concurrent.futures import ThreadPoolExecutor
is built on top of
threading