Use poll () on a new subprocess. List of objects

I'm trying to write some code that will poll a list of subprocess.Popen (?) Objects created as such:

self.processList = [subprocess.Popen for i in range(8)]

      

My code will create new subprocess.Popen objects and assign them to different places in the list. Then I can use poll () successfully. But before any of these codes take place, my new list of objects cannot be successfully polled. Is there a way to do this? I am polling the list to begin the next process, so I would like all of these functions to work correctly with the line of code above. This is what I am trying to accomplish before assigning anything to the above snooze:

print self.processList[position].poll()

      

Received error:

line 79, in jobQueue print self.processList [position] .poll () TypeError: unbound method poll () should be called with the Popen instance as the first argument (nothing happens instead)

And as mentioned, when I create a new object and put it in my list, I don't have this problem. I don't care what self.processList [0] .poll () returns, since it returns something and doesn't blow up at the beginning. Thank you so much for your help.

thank

Don

+3


source to share


1 answer


Your list does indeed have Popen classes, not objects:

>>> processList = [subprocess.Popen for i in range(1)]
>>> processList
[<class 'subprocess.Popen'>]

      



You need to call subprocess.Popen () to get the objects:

>>> processList = [subprocess.Popen('ls') for i in range(1)]
...
>>> processList
[<subprocess.Popen object at 0x7f31b77e4550>]

      

+1


source







All Articles