Skip to main content
Solved

Can we get process id of particular service starts through System Caller? Or can we trigger CLI request with user defined Process Name through System Caller?


rejith3119
Participant
Forum|alt.badge.img

I am using system caller in child workbench which trigger 3rd party service using command line and start the process e.g. abc.exe in windows. Sometimes process get stuck at their server and I am not able to get the status of the same, hence child workbench continue until any response gets from System caller. Is there any solution to kill the 3rd party process using windows process name or ID if its taking more than a particular time e.g. 1 hr?

Note: I am using FME Desktop with concurrent process of 3 jobs, so it should kill only the process which are not getting finished within 1 hr.

Can anyone help me on this?

Best answer by david_r

The SystemCaller is fairly simple and it doesn't return the process id.

For your use case, I would recommend using the PythonCaller rather than the SystemCaller.

Starting point:

import subprocess
 
def ProcessFeature(feature):
    process = subprocess.Popen(["echo""hello"])
    print(process.pid)

 

View original
Did this help you find an answer to your question?

5 replies

david_r
Celebrity
  • Best Answer
  • March 10, 2021

The SystemCaller is fairly simple and it doesn't return the process id.

For your use case, I would recommend using the PythonCaller rather than the SystemCaller.

Starting point:

import subprocess
 
def ProcessFeature(feature):
    process = subprocess.Popen(["echo""hello"])
    print(process.pid)

 


rejith3119
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • March 10, 2021
david_r wrote:

The SystemCaller is fairly simple and it doesn't return the process id.

For your use case, I would recommend using the PythonCaller rather than the SystemCaller.

Starting point:

import subprocess
 
def ProcessFeature(feature):
    process = subprocess.Popen(["echo""hello"])
    print(process.pid)

 

Hi @david_r​ ,

     Thank you for the quick response. I will try this one and will get back to you with the updates


rejith3119
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • March 12, 2021
rejith3119 wrote:

Hi @david_r​ ,

Thank you for the quick response. I will try this one and will get back to you with the updates

Hi @david_r​ ,

I am a fresher in python, so after exploring https://docs.python.org/3/library/subprocess.html#frequently-used-arguments, I could run below code with hard coded arguments like subprocess.Popen(["abc.exe", "arg1","arg2",....]), but its failing when I am running using 'arg' variable where cmd = ["abc.exe", "arg1","arg2",....]. Is there any syntax error?

import subprocess

 

def processFeature(feature):

  arg = feature.getAttribute('cmd')

  proc = subprocess.Popen(arg)

  feature.setAttribute("process_id",proc.pid)

  try:

    outs, errs = proc.communicate(timeout=120)

  except subprocess.TimeoutExpired:

    proc.kill()

    outs, errs = proc.communicate()

    feature.setAttribute("IsFailed","T")

 

Thanks in advance


david_r
Celebrity
  • March 12, 2021
rejith3119 wrote:

Hi @david_r​ ,

Thank you for the quick response. I will try this one and will get back to you with the updates

Just make sure 'arg' is a list, not a string. The function feature.getAttribute() does not return a list, unless you're referencing an FME list attribute.


rejith3119
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • March 15, 2021
rejith3119 wrote:

Hi @david_r​ ,

Thank you for the quick response. I will try this one and will get back to you with the updates

Thanks @david_r​  list method worked😊


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