The Multiprocessing Pool runs the entire code from the beginning, not the passed function. How to fix it?

I am implementing a function to convert a document to a pdf file of my Pyside6 project. I managed to do, however the program runs sequentially instead of in parallel, which means I can speed up the conversion process. For this I am using mpire with dill, because pickle can’t process something in the library I am using, but dill managed to.
So, the problem is that when I run WorkerPool, my program is executed from the beginning (start from main.py) instead of the process_object_of_project_pages_objects() function I specified. I don’t need this, because otherwise the code will generate errors related to the fact that initially the project for my program will not be selected, and therefore the database will not be created/selected (sqlite3.OperationalError: no such table: Project_pages_data).

converter.py (ignore the fact that n_jobs=1)

from mpire import WorkerPool

...

class ElementPool:
    def __init__(self, value):
        self.value = value

    def get_value(self):
        return self.value

...

class Converter:
     
    ...

    def get_list_of_created_pdf_pages(self, project_pages_objects) -> list:
        """
        Проход по project_pages_objects для преобразования каждой страницы в docx, а потом в pdf
        """
        log.obj_l.debug_logger(
            f"IN get_list_of_created_pdf_pages(project_pages_objects): project_pages_objects = {project_pages_objects}"
        )

        list_of_pdf_pages = list()

        project_pages_objects_for_pool = list()
        for object in project_pages_objects:
            project_pages_objects_for_pool.append(ElementPool(object))

        with WorkerPool(n_jobs=1, use_dill=True) as pool:
            results = pool.map(
                self.process_object_of_project_pages_objects,
                project_pages_objects_for_pool,
            )

        list_of_pdf_pages = [result for result in results if result]
        return list_of_pdf_pages

    
    def process_object_of_project_pages_objects(self, object_for_pool) -> dict:
        log.obj_l.debug_logger(
            f"IN process_object_of_project_pages_objects(object_for_pool): object_for_pool = {object_for_pool}"
        )
        object = object_for_pool.get_value()
        object_type = object.get("type")
        number_page = object.get("number_page")
        if object_type == "page":
            pdf_path = self.create_page_pdf(object.get("page"), True)
            return {"number_page": number_page, "pdf_path": pdf_path}
        return dict()

main.py

import package.app as app
import os
import sys

def main():
    current_directory = os.path.dirname(os.path.abspath(sys.argv[0]))
    app.App(current_directory)

if __name__ == "__main__":
    main()
 

It is expected that at any time when the project is open, the user clicks on the “Export to PDF” button, during which the methods in the file are executed converter.py
So, how can I fix this? Or are there analogues/other ways to do this in parallel to improve performance?

I’ve read this Why does pool run the entire file multiple times?
and this Multiprocessing Pool is running the whole code for every process created instead of just the function passed to it
but I haven’t figured out how it can be applied in my case.

New contributor

Artemako is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật