[issue34786] ProcessPoolExecutor documentation reports wrong exception being raised

Karthikeyan Singaravelan report at bugs.python.org
Mon Sep 24 08:51:52 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I think it raises BrokenThreadPool . A sample program that I tried as below raising an exception in the initializer. Maybe I am wrong here. Can you please attach a script that triggers BrokenProcessPool?

# bpo34786.py

import concurrent.futures
import time

def bar(i):
    raise Exception(i) # Raise exception from the initializer

def foo(i):
    time.sleep(i)
    return "1"

with concurrent.futures.ThreadPoolExecutor(max_workers=5,
                                           initializer=bar, initargs=(1,)) as executor:
    future_to_url = {executor.submit(foo, i, 60): i for i in range(10)}
    for future in concurrent.futures.as_completed(future_to_url):
        try:
            data = future.result()
        except Exception as exc:
            print('generated an exception: %s' % (exc))
        else:
            print('%d bytes' % (len(data)))

# Run the program

./python.exe ../backups/bpo34786.py
Exception in initializer:
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/concurrent/futures/thread.py", line 69, in _worker
    initializer(*initargs)
  File "../backups/bpo34786.py", line 5, in bar
    raise Exception(i)
Exception: 1
Exception in initializer:
Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/concurrent/futures/thread.py", line 69, in _worker
    initializer(*initargs)
  File "../backups/bpo34786.py", line 5, in bar
    raise Exception(i)
Exception: 1
Traceback (most recent call last):
  File "../backups/bpo34786.py", line 13, in <module>
    future_to_url = {executor.submit(foo, i, 60): i for i in range(10)}
  File "../backups/bpo34786.py", line 13, in <dictcomp>
    future_to_url = {executor.submit(foo, i, 60): i for i in range(10)}
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/concurrent/futures/thread.py", line 148, in submit
    raise BrokenThreadPool(self._broken)
concurrent.futures.thread.BrokenThreadPool: A thread initializer failed, the thread pool is not usable anymore



Thanks

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34786>
_______________________________________


More information about the Python-bugs-list mailing list