Jump to content

Multithreading and Multi processing for python script in Cura


VictorMic

Recommended Posts

Posted · Multithreading and Multi processing for python script in Cura

Hello,

I am currently developing a python script to increase E value directly in the Gcode, so I have to work on millions of lines. So i decide to add multiprocessing or multithreading to improve the time of execution. When I launch my program without multiprocessing on cura all is working, but i can't do multiprocessing/multithreading on Cura, it always return me empty list. Have you any advise ?

  • Link to post
    Share on other sites

    Posted · Multithreading and Multi processing for python script in Cura

    So the goal of my company is to create a new way to create industrial metal pieces by using 3d printing firstly to create the piece in plastic and with this plastic piece create a mold in which aluminium is poured and melt the plastic (so we need a 3d printing with the lowest density, so all the plastic will be burn by the aluminium.  I am currently creating a post processing python script for Cura, of which the goal is to increment the E value of the gcode to compensate for the loss of materials, that occur when the extruder of the 3d printer is moving without printing. We need to compensate these loss because otherwise it create holes in the printing. But the size of the pieces are great (millions of gcodes lines), so to be able to modify the gcode in a correct amount of time I used the Multiprocessing of python. I had to work on windows so to use multiprocessing i need to have this line :

    if __name__ == '__main__':  # MultiProcessing
            with Pool() as p:
                resultat = p.map(traitement_gcode_lineaire,liste_traitement)
        if len(resultat)!=0 :
            for result in resultat :
                fichier += result

    When launch by myself (like in VS code) without Cura all is good. But the issue here is that it can't enter the loop because __name__ will never be equal to '__main__', but it always equal to :

    'PostProcessingPlugin.PostProcessingPlugin.ModificationGcodeMultiProcessing'

    where 'ModificationGcodeMultiProcessing' is the name of my postprocessing script and i never found any other script that was using multiprocessing so i was wandering if anybody has any clue for me.

    I don t have any error message but at the end 'Fichier' (which should contain the gcode that i modify) is empty.

    I attach my code. But the issue is located in the function improve_extrusion (the other work perfectly)

    ModificationGcodeMultiProcessing.zip

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • UltiMaker Cura 5.8 beta released
        Another Cura release has arrived and in this 5.8 beta release, the focus is on improving Z seams, as well as completing support for the full Method series of printers by introducing a profile for the UltiMaker Method.
          • Like
        • 1 reply
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...