Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 7th, 2013, 06:21 AM
NewCoderBee NewCoderBee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 NewCoderBee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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................

Reply With Quote
  #2  
Old February 7th, 2013, 09:54 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,369 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 h 24 m 16 sec
Reputation Power: 383
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!

Reply With Quote
  #3  
Old February 7th, 2013, 10:49 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #4  
Old February 7th, 2013, 11:55 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,369 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 11 h 24 m 16 sec
Reputation Power: 383
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.

Reply With Quote
  #5  
Old February 8th, 2013, 01:40 AM
NewCoderBee NewCoderBee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 NewCoderBee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.......

Reply With Quote
  #7  
Old February 8th, 2013, 09:41 AM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 50 m 57 sec
Reputation Power: 7
Doug Hellmann's site is always a good place to try http://www.doughellmann.com/PyMOTW/...ing/basics.html

Last edited by dwblas : February 8th, 2013 at 09:43 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Subprocess in Python giving error!!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap