Proper way to stop nipype workflow programmatically

Is there a way to stop a workflow execution programmatically?
Using a kill signal to the python process works but is not very safe or elegant

Thanks

nipype doesn’t have a listener interface to do this. this is a good suggestion for a feature in pydra. i have hacked this in the past to monitor the contents of a file on the system within the workflow submission loop, but could likely be switched to listening on a port.

can you explain me how you did it?
did you rewrite the run() function of DistributedPluginBase to introduce a check for an external file? what was your approach to stop the workflow then? kill pending processes or something else?
thank you

indeed the changes were in that function and perhaps something in the specific scheduler as well (since each scheduler has a different way of canceling jobs). i had a local copy of nipype which was adjusted to read a file and then terminate all pending jobs. it was also specific at that time to our scheduler (SGE). this was created because we were individually running different workflows simultaneously and needed to remove just the relevant jobs of the workflow.

I have a similar situation where multiple workflows can be started by the same script. I resolved using an intermediate subprocesses which then call the workflows: in this way loggers and interfaces of different workflows don’t interact each other and I can kill the intermediate subprocess and all its children if I need to stop a specific workflow in case of error.

Thank you for your answare