Output of Popen.poll() is a long string

Recently I started to use Popen.poll() one of my simple Python programs in order to check if the process is finished before running the 2nd command which requires the 1st one to be finished.
It looks something like this, and it works fine with this code

    if proc[ind].poll() is None:
        print( "It is still running, so will wait" )
        time.sleep(30)

I have completely another python code, which executes different program (in Java), but in this case
the output of Popen.poll() is a long string

<bound method Popen.poll of <Popen: returncode: None args: [‘decoder -i /detectors/uRwell/2…>>

As a result the if proc[ind].poll() is None: never gets satisfied
I am wondering why it is not “None” or a number (like an exit code).
Is there any other way of checking if the given process is still running?

Below is my complete code in case you have time to read it.
Thanks!

import subprocess
import shlex
import os
import time
import glob
import sys


if len(sys.argv) != 2 :
    print( "Wrong syntax, exiting" )
    print( "The command should look like Decode_Run.py $Run" )
    exit(1)

processes = set()
run = int(sys.argv[1])

print( "The run is %d" %(run))

evio_DIR = "/detectors/uRwell/2022_2023_EEL_Data/"

files = glob.glob("%s/urwell_00%d.evio*" %(evio_DIR, run));

# will keep track of processes for each file, and run next step when then current step is finished
proc_decode = {} 

for curFile in files:

    #split the file name by ".evio." separator to get the file index
    splited_fname = curFile.split(".evio.")    
    file_ind = int( splited_fname[1] )
    
    cmd = "decoder -i %s -o Data/decoded_%d_%d.hipo -c 1" %( curFile, run, file_ind )
    
    print( "The command is %s"%(cmd) )
    proc_decode[file_ind] = subprocess.Popen([cmd], shell = True)

n_RunningProc = len(proc_decode)

proc_Skim = {} 

while n_RunningProc > 0:

    n_RunningProc = 0
    
    for curFile in files:

        #split the file name by ".evio." separator to get the file index
        splited_fname = curFile.split(".evio.")    
        file_ind = int( splited_fname[1] )

        # Let's check if the Decoding for this file is finished
        # if it is finished we will run the SkimZeroSuppression on it,
        # otherwise will wait 30 seconds and will try again

        print( "Poll is")
        print(proc_decode[file_ind].poll)
        
        if proc_decode[file_ind].poll is None:
            print( "The decoding of file %d is still running" %(file_ind) )
            n_RunningProc = n_RunningProc + 1
        else:
            cmd = "./SkimZeroSuppression.exe %d %d" %( run, file_ind )
            print( "The command is %s"%(cmd) )
            #proc_Skim[file_ind] = subprocess.Popen([cmd], shell = True)
    
    print("There are still %d decodings are running. Will wait a little bit." %(n_RunningProc))
    time.sleep(30)

print("\n\n All done")

I did a google search of <bound method Popen.poll of <Popen: returncode: , but didn’t find any post/issues with the same issue.

Leave a Comment