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 kahara
Recipients docs@python, kahara, xtreak
Date 2018-09-24.13:24:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537795446.51.0.956365154283.issue34786@psf.upfronthosting.co.za>
In-reply-to
Content
Perhaps I wasn't clear that this considered ProcessPoolExecutor documentation, not ThreadPoolExecutor. Taking the example from documentation and adding an initializer like this:


import concurrent.futures
import math

PRIMES = [
    112272535095293,
    112582705942171,
    112272535095293,
    115280095190773,
    115797848077099,
    1099726899285419]

def is_prime(n):
    if n % 2 == 0:
        return False

    sqrt_n = int(math.floor(math.sqrt(n)))
    for i in range(3, sqrt_n + 1, 2):
        if n % i == 0:
            return False
    return True

def init():
    raise Exception()

def main():
    with concurrent.futures.ProcessPoolExecutor(initializer=init) as executor:
        for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
            print('%d is prime: %s' % (number, prime))

if __name__ == '__main__':
    main()


...yields the following:


Exception in initializer:
Traceback (most recent call last):
  File "/Users/developer/cpython/Lib/concurrent/futures/process.py", line 219, in _process_worker
    initializer(*initargs)
  File "/tmp/bpo34786.py", line 25, in init
    raise Exception()
Exception
Exception in initializer:
Traceback (most recent call last):
  File "/Users/developer/cpython/Lib/concurrent/futures/process.py", line 219, in _process_worker
    initializer(*initargs)
  File "/tmp/bpo34786.py", line 25, in init
    raise Exception()
Exception
Exception in initializer:
Traceback (most recent call last):
  File "/Users/developer/cpython/Lib/concurrent/futures/process.py", line 219, in _process_worker
    initializer(*initargs)
  File "/tmp/bpo34786.py", line 25, in init
    raise Exception()
Exception
Exception in initializer:
Traceback (most recent call last):
  File "/Users/developer/cpython/Lib/concurrent/futures/process.py", line 219, in _process_worker
    initializer(*initargs)
  File "/tmp/bpo34786.py", line 25, in init
    raise Exception()
Exception
Traceback (most recent call last):
  File "/tmp/bpo34786.py", line 33, in <module>
    main()
  File "/tmp/bpo34786.py", line 29, in main
    for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
  File "/Users/developer/cpython/Lib/concurrent/futures/process.py", line 476, in _chain_from_iterable_of_lists
    for element in iterable:
  File "/Users/developer/cpython/Lib/concurrent/futures/_base.py", line 594, in result_iterator
    yield fs.pop().result()
  File "/Users/developer/cpython/Lib/concurrent/futures/_base.py", line 436, in result
    return self.__get_result()
  File "/Users/developer/cpython/Lib/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
History
Date User Action Args
2018-09-24 13:24:06kaharasetrecipients: + kahara, docs@python, xtreak
2018-09-24 13:24:06kaharasetmessageid: <1537795446.51.0.956365154283.issue34786@psf.upfronthosting.co.za>
2018-09-24 13:24:06kaharalinkissue34786 messages
2018-09-24 13:24:06kaharacreate