Python Forum
Launch another python command without waiting for a return.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launch another python command without waiting for a return.
#11
(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
[Image: NfRQr9R.jpg]
Reply
#12
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)
Reply
#13
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#14
Note that
from concurrent.futures import ThreadPoolExecutor
is built on top of threading
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pip stops waiting for python walker 6 970 Nov-28-2023, 06:55 PM
Last Post: walker
  Waiting for input from serial port, then move on KenHorse 2 834 Oct-17-2023, 01:14 AM
Last Post: KenHorse
  Launch Python IDLE Shell from terminal Pavel_47 5 1,143 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Waiting for heavy functions question philipbergwerf 14 3,278 Apr-29-2022, 07:31 PM
Last Post: philipbergwerf
  How to create waiting process? samuelbachorik 4 1,930 Sep-02-2021, 05:41 PM
Last Post: bowlofred
  Launch Windows Application OEMS1 0 2,096 Mar-26-2021, 07:42 PM
Last Post: OEMS1
Photo Python won`t launch error newbieee 0 1,734 Feb-02-2021, 11:51 PM
Last Post: newbieee
  Waiting and listening test 2 2,099 Nov-13-2020, 04:43 PM
Last Post: michael1789
  waiting for barcode scanner output, while main program continues to run lightframe109 3 4,585 Sep-03-2020, 02:19 PM
Last Post: DeaD_EyE
  waiting to connect Skaperen 9 3,467 Aug-17-2020, 05:58 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020