0

I am running the below code which runs a command line application which runs for about 40 mins. While this is running my QUIT button is not accessible so I am unable to quit the running application. The below code and the button are both seated in their own def. Any ideas as to how I can get a working quit button while my application is running?

command1 = transporterLink + " -m verify -f " + indir1 + " -u " + username + " -p " + password + " -o " + logPath + " -s " + provider1 + " -v eXtreme"
master, slave = pty.openpty()

process = Popen(command1, shell=True, stdin=PIPE, stdout=slave, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
global subject
subject = "Test"
while True:
    wx.Yield()
    line = stdout.readline()
    line = line.rstrip()
    print line
    if "Returning 1" in line:
        result1 = "Verify FAILED!"
        subject = "FAILED! - "
        self.sendEmail(self)
        break
    if "Returning 0" in line:
        result1 = "Verify PASSED!"
        subject = "PASSED! - "
        self.sendEmail(self)
        break
mzjn
  • 48,958
  • 13
  • 128
  • 248
speedyrazor
  • 3,127
  • 7
  • 33
  • 51

1 Answers1

0

stdout.readline is blocking until there is something in stdout. You could use select module's poll

command1 = transporterLink + " -m verify -f " + indir1 + " -u " + username + " -p " + password + " -o " + logPath + " -s " + provider1 + " -v eXtreme"
master, slave = pty.openpty()

process = Popen(command1, shell=True, stdin=PIPE, stdout=master, stderr=slave, close_fds=True)
stdout = os.fdopen(master)
import select
q = select.poll()
q.register(stdout,select.POLLIN)
global subject
subject = "Test"
while True:
    wx.Yield()
    events = q.poll(0)
    for fd, flags in events:
        assert(fd == stdout.fileno())
        line = stdout.readline()
        print line
        if "Returning 1" in line:
            result1 = "Verify FAILED!"
            subject = "FAILED! - "
            self.sendEmail(self)
            sys.exit(0)
        if "Returning 0" in line:
            result1 = "Verify PASSED!"
            subject = "PASSED! - "
            self.sendEmail(self)
            sys.exit(0)
Community
  • 1
  • 1
Rems
  • 4,837
  • 3
  • 27
  • 24
  • Cheers Rems, with your code I am getting line = line.rstrip() AttributeError: 'list' object has no attribute 'rstrip'. If I take that line out and just print I get an endless list of [(6,1)]. I can quit using the button, which is good but i'm not getting the printout now. – speedyrazor Feb 11 '14 at 20:43
  • Updated the code according to http://docs.python.org/2/library/select.html#select.poll.poll – Rems Feb 12 '14 at 17:25