How to terminate a python subprocess launched with shell=true?



How to terminate a python subprocess launched with shell=true?..

Answer / Naveen Dev Verma

To terminate a Python subprocess launched using `subprocess.Popen(..., shell=True)`, you can call the `terminate()` method on the process object, or use the `kill()` method if the process is unresponsive:nn``pythonnimport subprocessnp = subprocess.Popen('command', shell=True)n# If needed: p.terminate()nsystem('pkill -2 ' + p.pid)n``

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Why do we use join() function in python?

1 Answers  


Are sets hashable python?

1 Answers  


What do you understand by *args and **kwarg python?

1 Answers  


What is the output of the below program?

1 Answers  


What are different methods to copy an object in python?

1 Answers  


What is the use of numpy package?

1 Answers  


What will be the output of ['!!welcome!!']*2?

1 Answers  


What is the best code you can write to swap two numbers?

1 Answers  


Tell us what is the usage of help() and dir() function in python?

1 Answers  


What are args and kwargs in Python?

1 Answers  


Is python a procedural language?

1 Answers  


What are the basic elements of python?

1 Answers  


Categories