Python Multithreaded with MULTICORE [Solved]

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by vocx »

mnesarco wrote: Sat Jul 18, 2020 1:46 am ...
About a PR to FreeCAD, it is not clear where to put the file. I am not very familiar with internal FreeCAD code structure. ...
If this is truly independent of any workbench, then you could perhaps place it in src/3rdParty/, just like lazy_loader, which is a small class taken from the TensorFlow project.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
mnesarco
Posts: 475
Joined: Thu Mar 26, 2020 8:52 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by mnesarco »

vocx wrote: Sat Jul 18, 2020 3:00 am If this is truly independent of any workbench, then you could perhaps place it in src/3rdParty/, just like lazy_loader, which is a small class taken from the TensorFlow project.
It is independent. The only thing to change is the first code line

Code: Select all

from freecad.marz.extension import App, QtCore
to

Code: Select all

import FreeCAD as App
from PySide import QtCore
If you really think it is ready for general use, I can send the PR, but it could be advisable to wait some comments from people that use it in their own projects, I wrote it to solve a specific problem in MarzWorkbench and it works very well in that context. But I have no feedback from other devs/contexts.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by vocx »

mnesarco wrote: Sat Jul 18, 2020 3:12 am ...
But I have no feedback from other devs/contexts.
Well, I haven't used it. I would at least try it if it was already in the source, but otherwise we can wait for etrombly's feedback.

Truth is development in FreeCAD is perhaps wilder than you may expect; we add things without thinking too much about them because it's better to keep dynamic development going on. If it turns out it wasn't a good idea, we can remake or undo the changes, that's pretty much how we've gotten to this point (which is maybe a bit messy, but hey it's dynamic).
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
etrombly
Posts: 144
Joined: Thu Dec 05, 2019 6:50 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by etrombly »

mnesarco wrote: Sat Jul 18, 2020 3:12 am If you really think it is ready for general use, I can send the PR, but it could be advisable to wait some comments from people that use it in their own projects, I wrote it to solve a specific problem in MarzWorkbench and it works very well in that context. But I have no feedback from other devs/contexts.
I'll let you know once I've tested a little more. The only thing I changed so far is adding an isDone() method that just returns self._isTerminated so you don't have to block like in get().
User avatar
mnesarco
Posts: 475
Joined: Thu Mar 26, 2020 8:52 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by mnesarco »

etrombly wrote: Sat Jul 18, 2020 11:16 am I'll let you know once I've tested a little more. The only thing I changed so far is adding an isDone() method that just returns self._isTerminated so you don't have to block like in get().
Thank you for your feedback.
etrombly wrote: Sat Jul 18, 2020 11:16 am ... adding an isDone() method that just returns self._isTerminated so you don't have to block like in get().
Yes that version is pretty simplified and contains only needed things used in MarzWorkbench, I have started a more generic and complete version with support for signals/slots to monitor the threads but it is used in another internal project. I will explore the possibility to publish that version.
User avatar
mnesarco
Posts: 475
Joined: Thu Mar 26, 2020 8:52 pm

Re: Python Multithreaded with MULTICORE [Solved]

Post by mnesarco »

BTW, there is also a useful Worker implementation in ExtMan and it is 100% standalone also:

https://github.com/mnesarco/FreeCAD_Ext ... /worker.py

Usage

Code: Select all


# Define your task function
def mytask(...):
   ....
   return something

# If you want to be notified async, define a listener
def mylistener( data ):
  result, error, target = data
  ....

# Create a job with your task
job = Worker(mytask, ...)

# get result async [optional]
job.signals.finished.connect( mylistener )

# Start the job in another thread
job.start()

# get result blocking [optional]
result = job.get()
Post Reply