This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dktrkranz
Recipients dktrkranz
Date 2014-09-08.10:29:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410172185.62.0.239101325071.issue22361@psf.upfronthosting.co.za>
In-reply-to
Content
I have a program which waits for external events (mostly pyinotify events), and when events occur a new worker is created using concurrent.futures.ThreadPoolExecutor. The following snippet represents shortly what my program does:

from time import sleep
from concurrent.futures import ThreadPoolExecutor

def func():
    print("start")
    sleep(10)
    print("stop")

ex = ThreadPoolExecutor(1)

# New workers will be scheduled when an event
# is triggered (i.e. pyinotify events)
ex.submit(func)

# Dummy sleep
sleep(60)

When func() is complete, I'd like the underlying thread to be terminated. I realize I could call ex.shutdown() to achieve this, but this would prevent me from adding new workers in case new events occur. Not calling ex.shutdown() leads to have unfinished threads which pile up considerably:

(gdb) run test.py
Starting program: /usr/bin/python3.4-dbg test.py
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff688e700 (LWP 17502)]
start
stop
^C
Program received signal SIGINT, Interrupt.
0x00007ffff6e41963 in select () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) info threads
  Id   Target Id         Frame
  2    Thread 0x7ffff688e700 (LWP 17502) "python3.4-dbg" 0x00007ffff7bce420 in sem_wait () from /lib/x86_64-linux-gnu/libpthread.so.0
* 1    Thread 0x7ffff7ff1700 (LWP 17501) "python3.4-dbg" 0x00007ffff6e41963 in select () from /lib/x86_64-linux-gnu/libc.so.6
(gdb)

Would it be possible to add a new method (or a ThreadPoolExecutor option) which allows to join the underlying thread when the worker function returns?
History
Date User Action Args
2014-09-08 10:29:45dktrkranzsetrecipients: + dktrkranz
2014-09-08 10:29:45dktrkranzsetmessageid: <1410172185.62.0.239101325071.issue22361@psf.upfronthosting.co.za>
2014-09-08 10:29:45dktrkranzlinkissue22361 messages
2014-09-08 10:29:44dktrkranzcreate