Module processes
[hide private]
[frames] | no frames]

Source Code for Module processes

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2004 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23  from os import kill, popen3, system 
24  from popen2 import Popen3 
25   
26   
27 -class RelaxPopen3(Popen3):
28 - def __init__(self, cmd, capturestderr=0, bufsize=-1):
29 """Extended Popen3 class.""" 30 31 # Run the init function of the Popen3 class. 32 Popen3.__init__(self, cmd, capturestderr, bufsize)
33 34
35 - def kill(self, login_cmd=None, sig=9):
36 """Function for killing the child process.""" 37 38 # Don't do anything if the child process has already finished. 39 if self.poll() != -1: 40 return 41 42 # Kill the child process (or pass silently if the PID no longer exists). 43 try: 44 kill(self.pid, sig) 45 except: 46 pass 47 48 # Kill the relax process spawned by the thread. 49 if hasattr(self, 'relax_pid') and self.relax_pid != None: 50 # Kill command. 51 kill_cmd = 'kill -%s %s' % (sig, self.relax_pid) 52 53 # Remote relax process. 54 if login_cmd: 55 kill_cmd = login_cmd + " \"" + kill_cmd + "\"" 56 57 # Kill relax. 58 stdin, stdout, stderr = popen3(kill_cmd)
59