Use poll() on new subprocess.Popen object list

248 views Asked by At

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

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

My code will be creating new subprocess.Popen objects and assigning them to different locations in the list. I can then successfully use poll(). But before any of that code takes place, my new list of objects can not be polled successfully. Is there a way to do this? I poll the list to start the next process, so I'd like to have all of this functionality work properly with the line of code above. This is what I'm trying to accomplish before assigning anything to the above snipet:

print self.processList[position].poll()

The error I receive is:

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

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

Thanks

Don

1

There are 1 answers

2
Dan Cornilescu On BEST ANSWER

Your list actually contains Popen classes, not objects:

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

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

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