0

I am executing the following command in a python script:

#! /usr/bin/python

import shlex
import os
import subprocess
import string
import random
import signal



pro = subprocess.Popen("zcat production_dump_2013-09-16_12-00.sql.gz | PGPASSWORD=everything psql -d voylla_solr -h localhost -p 5432 -U nishant", shell=True)
pro.wait()
os.kill(pro.pid, signal.SIGTERM)

This gives me:

OSError: [Errno 3] No such process

I also tried using

pro = subprocess.Popen("zcat production_dump_2013-09-16_12-00.sql.gz | PGPASSWORD=everything psql -d voylla_solr -h localhost -p 5432 -U nishant", shell=True)
pro.wait()
pro.kill()

and this gives me:

OSError: [Errno 3] No such process

How do I kill the process after execution to execute next commands

1 Answer 1

1

Popen.wait waits for the process to terminate, so there is nothing left to kill once it returns.

Once a process exits, you're not supposed to "kill it". The only thing you're supposed to do is collect its return code, which Popen.wait does for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.