![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Location: Philadelphia, PA
Posts: 11
Rep Power: 0
![]() |
Any Suggestions?
Hello,
I have an app using wxPyhton for the GUI. I click the Run button that triggers a function that opens a process and starts the command shell on Windows XP. Then I use the Input and Output streams to send a command( mycommand.exe) and what information returns from that I place in a multiline textctrl on my GUI screen. Everything works fine except, I have a Pause button and a Stop button to pause and stop execution. When I click Run, my Run button stays highlighted and the GUI is unresponsive until the process completes, so I can't press the Pause or Stop buttons. Any suggestions on how I should code this in order to be able to hit the run button and while the process is running the commands and updating the textctrl after every command(which it does now), make the GUI available to click the Stop or Pause buttons. Thanks |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
What are you using for the inter-process communication? I'm not sure if wx.Process is available to you from wxPython, but if it is, you should not be using it. You should be using os.popen* or the subprocess module.
If you are using os.popen/subprocess, then chances are the non-blocking calls like os.system and os.popen are blocking because you're not holding on to the object. The destructor is being called because it's going out of scope, and that causes the blockage until the spawned application finishes. If that's not your problem, post a testcase (_not_ the whole of your code, just a small enough, fully functional example that lets us isolate the problem easily). |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2005
Location: Philadelphia, PA
Posts: 11
Rep Power: 0
![]() |
Here is a the piece of offending code. I updated it to use the subprocess module, instead of wx.process. It runs the cmd2000.exe command once and then stops and freezes. Can you see what is wrong? Thanks
for x in range((int(self.nextOpenRow))):
while True and not self.paused:
self.test.SetGridCursor(0, 0)
self.test.MakeCellVisible(0, 0)
self.commandCell = self.test.GetCellValue(currentRow, 0,)
self.cmdCell = self.test.GetCellValue(currentRow, 1,)
self.ipCell = self.test.GetCellValue(currentRow, 2,)
self.timestrCell = self.test.GetCellValue(currentRow, 3,)
self.sleepCell = self.test.GetCellValue(currentRow, 4,)
y = 0
p = Popen(["cmd.exe"], stdin=PIPE, stdout=PIPE)
while y < int(self.timestrCell):
p.stdin.write("cmd2000.exe %s \"resdiag %s\"\n" % (self.ipCell, self.cmdCell))
self.stream = p.stdout
text = self.stream.read()
self.out.AppendText(text)
time.sleep((int(self.sleepCell)))
y += 1
else:
self.test.MoveCursorDown(False)
currentRow = (currentRow + 1)
else:
self.run.Enable(True)
return |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
I really can't be sure as the example is a little too vague. `p` might be going out of scope and blocking. Please try and construct a minimal, fully working example that people can fiddle with like I suggested.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jul 2005
Location: Philadelphia, PA
Posts: 11
Rep Power: 0
![]() |
I can't post anything that will work, the program is really big spanning 3 different files. Also this is being written for a company, so I can't give out to much. I will play around with it, I was just seeing if you guys would notice something just from looking at this loop, this is whats doing the work, I can tell you what the variables are holding, not sure if that will help, but it won't hurt me to type them here if it doesn't. CommandCell and CmdCell are commands passed as args to cmd2000.exe, ipCell has an I.P address in it, timestrcell has a number which equals how many times to run a certain command, sleepcell is the number of seconds to sleep between each command. Thanks for trying.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|