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?

  • March 10, 2021
  • 5 replies
  • 75 views

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)

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

david_r
Celebrity
  • 8394 replies
  • 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
  • 7 replies
  • 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)

 

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
  • 7 replies
  • March 12, 2021

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
  • 8394 replies
  • March 12, 2021

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
  • 7 replies
  • March 15, 2021

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😊