Skip to main content
Question

Process triggered from System Caller does not end when workspace aborted

  • February 25, 2019
  • 9 replies
  • 40 views

virtualcitymatt
Celebrity
Forum|alt.badge.img+39

Hi all,

 

I've been playing around with the system caller, however, I've found that when I abort my FME process the process triggered using the System Caller keeps running.

 

 

Part of the problem is that I'm also using the TempPathnameCreator as the output for the called process, if I kill the FME process and the sub-process keeps running then the temp files also don't get deleted.

 

 

I have to manually kill and then delete the process

 

 

Does anyone know of a workaround for this?

9 replies

david_r
Celebrity
  • February 25, 2019

How are you starting the child process in the SystemCaller? If you can get hold of the process id (pid) you can make FME wait for process termination using e.g. a PythonCaller.

Here's an example that takes a list of process ids (pid_list{}) and wait until they've all terminated before the trigger feature is output:

import subprocess
import timeclass
FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        while True:
            process_ids = feature.getAttribute('pid_list{}')
            subprocess_lines = [line.split() for line in subprocess.check_output("tasklist").splitlines()]
            running_process_ids = [line[1for line in subprocess_lines if len(line) > 1]
            is_running = any(running is True for running in [i in running_process_ids for i in process_ids])
            if is_running:
                time.sleep(3)
            else:
                break
        self.pyoutput(feature)
    def close(self):
        pass

david_r
Celebrity
  • February 25, 2019
david_r wrote:

How are you starting the child process in the SystemCaller? If you can get hold of the process id (pid) you can make FME wait for process termination using e.g. a PythonCaller.

Here's an example that takes a list of process ids (pid_list{}) and wait until they've all terminated before the trigger feature is output:

import subprocess
import timeclass
FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        while True:
            process_ids = feature.getAttribute('pid_list{}')
            subprocess_lines = [line.split() for line in subprocess.check_output("tasklist").splitlines()]
            running_process_ids = [line[1for line in subprocess_lines if len(line) > 1]
            is_running = any(running is True for running in [i in running_process_ids for i in process_ids])
            if is_running:
                time.sleep(3)
            else:
                break
        self.pyoutput(feature)
    def close(self):
        pass

The code above takes the output from the command "tasklist" and splits out the process ids. If you prefer, it's also fairly easy to make it look for the name of the executable by changing the index on line 10 above from 1 to 0:

running_process_ids = [line[0]  for ...

virtualcitymatt
Celebrity
Forum|alt.badge.img+39
david_r wrote:

How are you starting the child process in the SystemCaller? If you can get hold of the process id (pid) you can make FME wait for process termination using e.g. a PythonCaller.

Here's an example that takes a list of process ids (pid_list{}) and wait until they've all terminated before the trigger feature is output:

import subprocess
import timeclass
FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        while True:
            process_ids = feature.getAttribute('pid_list{}')
            subprocess_lines = [line.split() for line in subprocess.check_output("tasklist").splitlines()]
            running_process_ids = [line[1for line in subprocess_lines if len(line) > 1]
            is_running = any(running is True for running in [i in running_process_ids for i in process_ids])
            if is_running:
                time.sleep(3)
            else:
                break
        self.pyoutput(feature)
    def close(self):
        pass

Thanks @david_r,

 

The process is a java program where the call is something like  "java -jar '<some jar file>' -'<some parameters>'"

 

So the process is java.exe - I could look for and kill the pid relating to a java.exe process if, and only if, there is a single java.exe running. This might be my only option as you say, unless you know of a way to get the ProcessID for something triggered by the SystemCaller with Python...?

 

 

Ideally it would be great if there was something I'm missing in the system caller to avoid the need, but perhaps that's wishful thinking :D

david_r
Celebrity
  • February 25, 2019
virtualcitymatt wrote:

Thanks @david_r,

 

The process is a java program where the call is something like "java -jar '<some jar file>' -'<some parameters>'"

 

So the process is java.exe - I could look for and kill the pid relating to a java.exe process if, and only if, there is a single java.exe running. This might be my only option as you say, unless you know of a way to get the ProcessID for something triggered by the SystemCaller with Python...?

 

 

Ideally it would be great if there was something I'm missing in the system caller to avoid the need, but perhaps that's wishful thinking :D

It may be easier to just skip the SystemCaller and start your java app using the subprocess.Popen() function in Python: it will return the pid for you to use later on, without having to guess based on the tasklist.


virtualcitymatt
Celebrity
Forum|alt.badge.img+39
david_r wrote:

It may be easier to just skip the SystemCaller and start your java app using the subprocess.Popen() function in Python: it will return the pid for you to use later on, without having to guess based on the tasklist.

Ok thanks David, I appreciate the suggestions.

 

Cheers

harmen_kampinga
Forum|alt.badge.img+2

That's also one of my issues when I trigger an executable

If the executable has run fairly , the SystemCaller won't end... it keeps running

Also when I stop the workspace running


harmen_kampinga
Forum|alt.badge.img+2

Another thing / question, related to this one: my batch file or my executable are finished running, but the system caller is still running. So the process in Workspace is not continuing. Is this a related problem or a new question? @david_r @virtualcitymatt ?


david_r
Celebrity
  • March 1, 2019
harmen_kampinga wrote:

Another thing / question, related to this one: my batch file or my executable are finished running, but the system caller is still running. So the process in Workspace is not continuing. Is this a related problem or a new question? @david_r @virtualcitymatt ?

Difficult to say without knowing exactly what process you're starting, and how you're starting it...


harmen_kampinga
Forum|alt.badge.img+2
david_r wrote:

Difficult to say without knowing exactly what process you're starting, and how you're starting it...

I'll show my developer it first, then I will get back on it

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings