The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Subprocess in Python giving error!!!
Discuss Subprocess in Python giving error!!! in the Python Programming forum on Dev Shed. Subprocess in Python giving error!!! Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2013, 06:21 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 40 m 5 sec
Reputation Power: 0
|
|
|
Subprocess in Python giving error!!!
Hello,
I am a beginner in Python scripting. I tried run/executing two programs simultaneously and it gave following error after printing few output lines.
Code:
Starting with the Basic code
a = -2
b = 0.0
c = 0.0
total = 0
1360238044.98
a = -2.0
b = 1.02
c = 0.51
total = 0.0
1360238048.01
Traceback (most recent call last):
File "C:/AKS/Subprocess/ex_prog01.py", line 43, in <module>
root = Myprog()
File "C:/AKS/Subprocess/ex_prog01.py", line 9, in __init__
self.Task_03()
File "C:/AKS/Subprocess/ex_prog01.py", line 38, in Task_03
q = subprocess.Popen(self.Task_02())
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 852, in _execute_child
args = list2cmdline(args)
File "C:\Python27\lib\subprocess.py", line 580, in list2cmdline
for arg in seq:
TypeError: 'NoneType' object is not iterable
i am using python 2.7 and is installed on windows 7 machine.
Following is the code which i have tried with
Code:
import subprocess, time
class Myprog:
def __init__(self,master=None):
self.Task_03()
def Task_01(self):
v1 = 'Hello there'
for x in range(1):
time.sleep(2)
print "\n", v1
def Task_02(self):
a = 1
b = 1
c = 1
for i in range(2):
total = ( a + b ) * c / (a + b + c)
a = total - 2
c = i * 0.51
b = 2 * c
time.sleep(3)
print "\na = ", a
print "\nb = ", b
print "\nc = ", c
print "\ntotal = ", total
print "\n", time.time()
def Task_03(self):
print "\nStarting with the Basic code"
q = subprocess.Popen(self.Task_02())
p = subprocess.Popen(self.Task_01())
print "\n\t\t\t\tEnd!!!!!"
root = Myprog()
root.mainloop()
Thanks in advance................
|

February 7th, 2013, 09:54 AM
|
 |
Contributing User
|
|
|
|
The fragment you've posted is bizarre. However, I understand the error. Quote: subprocess documentation
class subprocess.Popen(args, ...
args should be a sequence of program arguments or else a single string. |
Either way, the first argument to Popen is iterable. You, however, passed the result of method Task_02. Task_02 doesn't have a return statement and therefore returns None . Because that's how python works. If you think your program did anything more than this up to the error
Code:
import time
a = 1
b = 1
c = 1
for i in range(2):
total = ( a + b ) * c / (a + b + c)
a = total - 2
c = i * 0.51
b = 2 * c
time.sleep(3)
print "\na = ", a
print "\nb = ", b
print "\nc = ", c
print "\ntotal = ", total
print "\n", time.time()
then you're just about wrong.
__________________
[code] Code tags[/code] are essential for python code!
|

February 7th, 2013, 10:49 AM
|
|
Contributing User
|
|
Join Date: May 2009
Posts: 294
  
Time spent in forums: 3 Days 18 h 50 m 57 sec
Reputation Power: 7
|
|
Quote: | I tried run/executing two programs simultaneously | Subprocess will not run 2 things at once. It will run the first, and when it is finished, run the second. Multiprocessing or threading will start more than one thing at a time.
|

February 7th, 2013, 11:55 AM
|
 |
Contributing User
|
|
|
|
|
Subprocess will not run 2 things at once---but you can cheat.
In windows/unix you can run gui programs using
start excel
command &
but anyway the code of original post surely looked like a smash of misunderstood concepts.
|

February 8th, 2013, 01:40 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 40 m 5 sec
Reputation Power: 0
|
|
|
Thank you for your comments and input.
And yes i am having a lot of misconception about this in Python.
My aim is to run two or more process simultaneously(parallel), can you please suggest the way to do it in python.
Regards.......
|

February 8th, 2013, 08:43 AM
|
 |
Contributing User
|
|
|
|
|

February 8th, 2013, 09:41 AM
|
|
Contributing User
|
|
Join Date: May 2009
Posts: 294
  
Time spent in forums: 3 Days 18 h 50 m 57 sec
Reputation Power: 7
|
|
|
Last edited by dwblas : February 8th, 2013 at 09:43 AM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|