0

I am trying to run some example code, but I got a next result:

A process in the process pool was terminated abruptly while the future was running or pending.

I tried in Google Colab and everything runs fine, but when I'm in Jupyter, it says that it's not possible. I'm from Ananconda, using the Jupyternotebook in IOS.

For example: this code

import concurrent.futures
import math

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

def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    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 main():
    with concurrent.futures.ProcessPoolExecutor() as executor:
        for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)):
            print('%d is prime: %s' % (number, prime))

if __name__ == '__main__':
    main()

What should I do? What does the error mean?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    I just copied your code into file and run `python tmp.py`, and - believe me or not - it works. Please provide more details on your environment (works on ubuntu 22.04, python 3.10.8 installed via pyenv). I'm voting to close as "not reproducible", but if it continues failing for you - the correct reason is "needs debugging details". Anyway, this can't be answered without more context. – STerliakov Dec 26 '22 at 23:40
  • 1
    Probably related: https://stackoverflow.com/questions/15900366/all-example-concurrent-futures-code-is-failing-with-brokenprocesspool – STerliakov Dec 26 '22 at 23:41
  • I am trying with your suggestions but I got the same problem. I am in Jupyter 6.1.4. Version. I am in IOS. – Francisco Minchala Fajardo Dec 27 '22 at 00:37
  • Also, I am trying with others examples from internet, and the problem continues. I need that run in jupyter notebook. – Francisco Minchala Fajardo Dec 27 '22 at 00:41

0 Answers0