pieper / SlicerParallelProcessing

Slicer modules for running subprocesses to operate on data in parallel
Other
11 stars 5 forks source link

Example needed for getting results after logic in finished #2

Open BishopWolf opened 4 years ago

BishopWolf commented 4 years ago

If you try to get data after logic.run(), you will realize it is executed regardless of the logic not being finished yet. One way handle this case you need to do this in the callback method, but it is extremely difficult to do this. The other way is to use with sentences, the logic will no call exit until it finishes and the it will still be visible under context manager

pieper commented 4 years ago

logic.run() is intended to be non-blocking and should stay that way.

By adding a callback, the user of the class can perform an operation when all processes complete.

Alternatively, you can add an observer to the module node and get an event every time a process state changes. This is what the GUI does to update the status display.

The other way is to use with sentences, the logic will no call exit until it finishes and the it will still be visible under context manager

I don't understand - what are sentences in this context?

BishopWolf commented 4 years ago

Watch the modified test examples

pieper commented 4 years ago

I'm still not following. Can you describe more specifically what you are trying to achieve and why it is not possible with the current master branch? If it helps, make a new branch and pull request with the specific suggested changes.

BishopWolf commented 4 years ago

The proposed change was to have logic.run() as blocking until everything finishes, then it outputs results after the with statement. The current examples leave orphans QProcesses that finish themselves way after the script has finished. I propose you to have the two behaviours:

BishopWolf commented 4 years ago

I don't understand - what are sentences in this context?

The following is a with sentence

with ProcessesLogic(windowTitle=labelText) as logic:
    logic.run()
pieper commented 4 years ago

Okay, I see. Well, as I said I don't really see a need for a blocking version. As I mentioned, you can observe the node to track progress, or provide the callback to perform an operation when the processes all complete. Do you have a use case that cannot be satisfied with the existing behavior?

BishopWolf commented 4 years ago

Do you have a use case that cannot be satisfied with the existing behavior?

Most of my use cases require blocking, I have pushed some changes to add blocking functionality without making it the default. Also I have added the function I use for terminate (I have a progressbar with a cancel button).