keitazoumana/Medium-Articles-Notebooks

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

Opened this issue · 0 comments

Error: concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

Expected Result: All images of the PDF to be outputted as images

What is happening: Whenever I run the code

`def convert_pdf_to_images(file_path, scale=300/72):

pdf_file = pdfium.PdfDocument(file_path)

page_indices = [i for i in range(len(pdf_file))]

renderer = pdf_file.render(
    pdfium.PdfBitmap.to_pil,
    page_indices = page_indices, 
    scale = scale,
)

final_images = [] 

for i, image in zip(page_indices, renderer):
    
    image_byte_array = BytesIO()
    image.save(image_byte_array, format='jpeg', optimize=True)
    image_byte_array = image_byte_array.getvalue()
    final_images.append(dict({i:image_byte_array}))

return final_images`

The code will not run and is giving this error.

` An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.`