[Python] Avoid PicklingError using multiprocessing in Python 3.8 libreoffice macro

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use multiprocessing in a LibreOffice Macro in Python 3.8. When I create a Macro it is part of the 'ooo_script_framework' module. So, when the process is pickled it is in fact part of an object which is not pickelable.

    "Can't pickle \<function task at 0x0000017B53415AF0\>: import of module 'ooo_script_framework' failed"


    I'd like to be able to make the function declared in the main process instead without any link to the module.

    MyMacro.py :

    import multiprocessing as mp
    import time

    def tack():
    with open("./test.txt", "w") as f:
    f.write("toto")

    def MyMacro():
    p = mp.Process(task)
    p.start()
    time.sleep(1)
    p.stop()


    It seems that MyMacro.py is somehow copied into something like ooo_script_framework.py.

    ooo_script_framework.py :

    insert MyMacro.py


    How to make the interpreter not able to see ooo_script_framework.task(), but just tack()?

    Continue reading...

Compartilhe esta Página