I am making Popen call as below. And yes I need shell=True.
f = tempfile.TemporaryFile(suffix = ".txt", prefix = "Result_", dir = tempfile.gettempdir(), delete = False)
pp = psutil.Popen(run, shell = True, stderr = f, stdin = subprocess.PIPE, stdout = subprocess.PIPE).
(data, err) = pp.communicate()
My run command is bit complicated but basically it runs below function which in turn runs a report and writes to a file.
def query():
pickledef = sys.argv[1:]
pickledef = ''.join(pickledef)
with open(pickledef, 'rb') as f:
querydef = pickle.load(f)
results = run_report(report_def)
out_file_name = to_file(results)
sys.stdout.write('<FILENAME>' + out_file_name)
I am making the Popen call in a loop and I intend to run multiple queries in a batch. I tried running two reports and they run perfectly fine as I see the files are created with output result. However, the program gets stuck ( I think at communicate()) for some unknown reasons. I know communicate isn't the best option if the expected output is large, but I am already addressing this issue by writing the result in a file. So I am kinda lost why this isn't working. Any help is appreciated. please let me know if anything isn't clear.
Thanks