commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r7903 - in grc/branches/grc_reloaded: notes src/grc sr


From: jblum
Subject: [Commit-gnuradio] r7903 - in grc/branches/grc_reloaded: notes src/grc src/grc/platforms/gnuradio_python
Date: Fri, 29 Feb 2008 12:02:05 -0700 (MST)

Author: jblum
Date: 2008-02-29 12:02:04 -0700 (Fri, 29 Feb 2008)
New Revision: 7903

Modified:
   grc/branches/grc_reloaded/notes/todo.txt
   grc/branches/grc_reloaded/src/grc/ActionHandler.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
Log:
switched from popen2 to subprocess for flow graph exec

Modified: grc/branches/grc_reloaded/notes/todo.txt
===================================================================
--- grc/branches/grc_reloaded/notes/todo.txt    2008-02-29 18:19:34 UTC (rev 
7902)
+++ grc/branches/grc_reloaded/notes/todo.txt    2008-02-29 19:02:04 UTC (rev 
7903)
@@ -1,6 +1,4 @@
 ############ GRC Reloaded: #############
-reload(usrp) in usrp diagnostics
-usrp diagnostics in scripts (separate from grc)
 generate button next to execute
 dtd for saved flow graphs
 pid file in generator

Modified: grc/branches/grc_reloaded/src/grc/ActionHandler.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-02-29 18:19:34 UTC 
(rev 7902)
+++ grc/branches/grc_reloaded/src/grc/ActionHandler.py  2008-02-29 19:02:04 UTC 
(rev 7903)
@@ -301,7 +301,7 @@
                                        ExecFlowGraphThread(self)       #only 
exec if file path and saved
                elif state == FLOW_GRAPH_STOP:
                        if self.get_page().get_pid_file(): 
-                               try: 
os.kill(int(open(self.get_page().get_pid_file(), 'r').read()), 9)
+                               try: os.kill(self.get_page().get_pid_file(), 9)
                                except: print "could not kill pid file: 
%s"%self.get_page().get_pid_file()
                elif state == '': #pass and run the global actions
                        pass
@@ -339,24 +339,23 @@
                self.flow_graph = action_handler.get_flow_graph()
                #store page and dont use main window calls in run
                self.page = action_handler.get_page()
-               #random id so multiple flow graphs can run w/o files 
intersecting
-               rand_id = random.randint(10000, 99999) 
-               #set pid file   
-               pid_file = '/tmp/grc-%d-%d.pid'%(os.getpid(), rand_id)          
-               self.page.set_pid_file(pid_file)
-               #update
-               self.update_exec_stop()
+               #get generator
+               generator = 
self.flow_graph.get_parent().get_generator()(self.flow_graph)
                Messages.send_start_exec(self.page.get_file_path())
-               self.start()
+               #get the popen
+               try: 
+                       self.p = generator.get_popen(self.page.get_file_path())
+                       self.page.set_pid_file(self.p.pid)
+                       #update
+                       self.update_exec_stop()
+                       self.start()
+               except Exception, e:
+                       Messages.send_end_exec([str(e)])                        
                
        def run(self):  
-               """Execute the flow graph."""
-               #get generator
-               generator = self.flow_graph.get_parent().get_generator()
-               #execute generator
-               lines = 
generator(self.flow_graph).execute(self.page.get_file_path(), 
self.page.get_pid_file())
+               """Wait on the flow graph."""           
                #handle completion
-               Messages.send_end_exec(lines)   
+               Messages.send_end_exec(self.p.stderr.readlines())       
                self.page.set_pid_file('')
                self.update_exec_stop()
                

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-29 18:19:34 UTC (rev 7902)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-29 19:02:04 UTC (rev 7903)
@@ -21,7 +21,7 @@
 address@hidden Josh Blum
 
 import os
-import popen2
+import subprocess
 import sys
 from Cheetah.Template import Template
 from grc.Constants import FLOW_GRAPH_FILE_EXTENSION
@@ -41,29 +41,22 @@
        
        def __init__(self, flow_graph):
                self._flow_graph = flow_graph
-               self._pid_file = ''
                
-       def execute(self, file_path, pid_file=''):
+       def get_popen(self, file_path):
                """!
                Generate and execute this python flow graph.
                @param file_path the file path of the flow graph
-               @param pid_file the optional pid file to write to
-               @return a list of errors
+               @return a popen object
                """
-               self._pid_file = pid_file
-               exec_file = file_path.replace(FLOW_GRAPH_FILE_EXTENSION, '.py')
+               exec_file = file_path.replace(FLOW_GRAPH_FILE_EXTENSION, '') + 
'.py'
                #generate file
-               try: open(exec_file, 'w').write(str(self))
-               except: return ["Could not generate file."]
+               open(exec_file, 'w').write(str(self))
                #execute
-               cmd = '%s %s'%(PYEXEC, exec_file)
+               cmds = [PYEXEC, exec_file]
                if self._flow_graph.get_option('generate_options') == 'no_gui':
-                       cmd = 'xterm -e ' + cmd                 
-               p = popen2.Popen3(cmd=cmd, capturestderr=True)
-               try: os.remove(self._pid_file)
-               except: print "could not remove pid file: %s"%self._pid_file
-               #read all the lines of the stderr into a list
-               return p.childerr.readlines()
+                       cmds = ['xterm', '-e'] + cmds                   
+               p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, shell=False, universal_newlines=True)
+               return p
                                
        def __str__(self):
                """!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]