0

i want to make a system call in my python code but the problem is that it breaks the sequence of my original code..

for ex.

def call_host(self):
    self.builder.get_object("windowMain").show()         
    os.system('python Adder.py')
    self.builder.get_object("window1").show()

in above pygtk code once Adder.py is called next line wont execute i want system to execute adder.py and come back to my original code... thnx in advance

Here is my code for Adder.py

import sys
try:  
    import pygtk  
    pygtk.require("2.0")  
except:  
    pass  
try:  
    import gtk  
except:  
    print("GTK Not Availible")
    sys.exit(1)

class adder:
    result = 0

    def __init__( self, number1, number2 ):    
        return None            

    def giveResult( self,number1,number2 ):    
        self.result = int( number1 ) + int( number2 )    
        return str(self.result)

class adderGui:    
    def __init__( self ):    
        self.builder = gtk.Builder()    
        self.builder.add_from_file("Adder.glade")

        dic = { 
            "on_buttonQuit_clicked" : self.quit,    
            "on_buttonAdd_clicked" : self.add,    
            "on_windowMain_destroy" : self.quit,    
        }

        self.builder.connect_signals( dic )

    def add(self, widget):    
        entry1 = self.builder.get_object ("entry1")    
        entry2 = self.builder.get_object ("entry2")

        try:    
            thistime = adder( entry1.get_text(), entry2.get_text() )
        except ValueError:    
            self.builder.get_object("hboxWarning").show()    
            self.builder.get_object("entryResult").set_text("ERROR")    
            return 0

        self.builder.get_object("hboxWarning").show()

        #self.builder.get_object("image1").hide()

        self.builder.get_object("entryResult").set_text(
            thistime.giveResult(entry1.get_text(), entry2.get_text())
        )

    def quit(self, widget):    
        sys.exit(0)

adderGui = adderGui()    
gtk.main()
1
  • why the code of Adder.py is important? couldn't it be any script? Commented Mar 28, 2012 at 16:29

2 Answers 2

1

If you use subprocess.Popen, your main program will continue running without "blocking" until the subprocess terminates.

Sign up to request clarification or add additional context in comments.

Comments

1

os.system will run a command in a subprocess and wait for it to finish before running. If you want to run it in parallel with the parent process, then you should look at the subprocess module -- in particular, you'll want to create a subprocess.Popen object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.