SOLVED Error Multiprocessing in RF


  • admin

    DrawBot PR to improve asyncio: https://github.com/typemytype/drawbot/pull/392

    this allows to create a task in a run loop:

    # will not work in RF3.4 or DB1.126 but will work in the next releases!! 
    import asyncio
    
    async def count():
        print("One")
        await asyncio.sleep(10)
        print("Two")
    
    async def main():
        await asyncio.gather(count(), count(), count())
    
    if __name__ == "__main__":
        asyncio.create_task(main())
    

  • admin

    found it!!

    in RF and DB the main module must be the py file starting the app!

    import sys
    
    print(sys.modules["__main__"])
    

    while when you run your code in terminal the __main__ module is the file itself...

    do an import of the your multiprocessing code instead.


  • admin

    why it worked in DrawBot, I dont know.. Could be the switch between py2 -> py3.6 -> py3.7... Do you have a DrawBot version number?


  • admin

    asyncio support can be improved, will try out some bit and pieces.

    Threading, multiprocessing is harder with user interaction and with the bridge between python and cocoa...

    FontGoggles uses https://github.com/alberthier/corefoundationasyncio



  • @frederik And for what it's worth, the multiprocessing scripts don't seem to work in the standalone Drawbot app either, same error. So whatever the issue is in RF, it seems like it's the same in DrawBot.

    I tried it in DrawBot because I seem to remember trying multiprocessing a year ago for a drawbot thing after seeing this post https://forum.drawbot.com/topic/150/drawbot-multiprocessing?_=1591994686928

    and it worked back then! I wonder what changed?



  • @frederik I see, so not much hope for this specific issue to be fixed?

    Essentially where I was hoping to go with this is I think it would be great to somehow run a process in the background without RoboFont locking up the interface. Even this simple asyncio example, while it does execute in parallel, causes RoboFont to "beachball" while the process completes.

    import asyncio
    
    async def count():
        print("One")
        await asyncio.sleep(10)
        print("Two")
    
    async def main():
        await asyncio.gather(count(), count(), count())
    
    if __name__ == "__main__":
        import time
        s = time.perf_counter()
        asyncio.run(main())
        elapsed = time.perf_counter() - s
        print(f"{__file__} executed in {elapsed:0.2f} seconds.")
    

    Is there any way to spawn a process or run a script, maybe on another core (I have 8 cores on this iMac, RoboFont only runs on 1), that runs in the background, and doesn't block RF's other processes?


  • admin

    I see...

    asyncio examples does work... I assume, without doing to much research, the issue is related to the combo with pyObject and an already running runloop. RoboFont is one big runloop.



  • @frederik No, it still gives the same error whether or not it is run from a file via the Scripts menu or through the Python Scripting Window :/



  • @frederik Oh ok, I'll try that in a minute!


  • admin

    have to dive into how RF executes py code, but I guess this solved when you run th py from a file that is saved...


Log in to reply