Back to index

salome-kernel  6.5.0
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes
runSalome.InterpServer Class Reference
Inheritance diagram for runSalome.InterpServer:
Inheritance graph
[legend]
Collaboration diagram for runSalome.InterpServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def run
def initArgs
def daemonize

Static Public Member Functions

def set_server_launch_mode

Public Attributes

 args
 CMD
 PID
 ARGS

Static Public Attributes

string server_launch_mode = "daemon"

Detailed Description

Definition at line 91 of file runSalome.py.


Constructor & Destructor Documentation

def runSalome.InterpServer.__init__ (   self,
  args 
)

Reimplemented from server.Server.

Definition at line 92 of file runSalome.py.

00092 
00093     def __init__(self,args):
00094         self.args=args
00095         if sys.platform != "win32":
00096           env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
00097           self.CMD=['xterm', '-e']+ env_ld_library_path + ['python']
00098         else:
00099           self.CMD=['cmd', '/c', 'start cmd.exe', '/K', 'python']
       

Member Function Documentation

def server.Server.daemonize (   self,
  args 
) [inherited]

Definition at line 88 of file server.py.

00088 
00089     def daemonize(self,args):
00090         # to daemonize a process need to do the UNIX double-fork magic
00091         # see Stevens, "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177)
00092         # and UNIX Programming FAQ 1.7 How do I get my program to act like a daemon?
00093         #     http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
00094         #open a pipe
00095         c2pread, c2pwrite = os.pipe()
00096         #do first fork
00097         pid=os.fork()
00098         if pid > 0:
00099           #first parent
00100           os.close(c2pwrite)
00101           #receive real pid from child
00102           data=os.read(c2pread,24) #read 24 bytes
00103           os.waitpid(pid,0) #remove zombie
00104           os.close(c2pread)
00105           # return : first parent
00106           childpid=int(data)
00107           if childpid==-1:
00108             return None
00109           try:
00110             os.kill(childpid,0)
00111             return childpid
00112           except:
00113             return None
00114 
00115         #first child
00116         # decouple from parent environment
00117         os.setsid()
00118         os.close(c2pread)
00119 
00120         # do second fork : second child not a session leader
00121         try:
00122           pid = os.fork()
00123           if pid > 0:
00124             #send real pid to parent
00125             os.write(c2pwrite,"%d" % pid)
00126             os.close(c2pwrite)
00127             # exit from second parent
00128             os._exit(0)
00129         except OSError, e:
00130           print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
00131           os.write(c2pwrite,"-1")
00132           os.close(c2pwrite)
00133           sys.exit(1)
00134 
00135         #I am a daemon
00136         os.close(0) #close stdin
00137         os.open("/dev/null", os.O_RDWR)  # redirect standard input (0) to /dev/null
00138         try:
00139           os.execvp(args[0], args)
00140         except OSError, e:
00141           if args[0] != "notifd":
00142             print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror)
00143             pass
00144           os._exit(127)

Here is the caller graph for this function:

def server.Server.initArgs (   self) [inherited]

Reimplemented in nameserver.NamingServer.

Definition at line 39 of file server.py.

00039 
00040     def initArgs(self):
00041         self.PID=None
00042         self.CMD=[]
00043         self.ARGS=[]
00044         if self.args.get('xterm'):
00045           if sys.platform != "win32":
00046             self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold']
00047           else:
00048             self.ARGS=['cmd', '/c', 'start  cmd.exe', '/K']

Reimplemented from server.Server.

Definition at line 100 of file runSalome.py.

00100 
00101     def run(self):
00102         global process_id
00103         command = self.CMD
00104         print "INTERPSERVER::command = ", command
00105         if sys.platform == "win32":
00106           import win32pm
00107           pid = win32pm.spawnpid( string.join(command, " "),'-nc' )
00108         else:
00109           pid = os.spawnvp(os.P_NOWAIT, command[0], command)
00110         process_id[pid]=self.CMD
00111         self.PID = pid
00112 
00113 # ---

def server.Server.set_server_launch_mode (   mode) [static, inherited]

Definition at line 54 of file server.py.

00054 
00055     def set_server_launch_mode(mode):
00056       if mode == "daemon" or mode == "fork":
00057         Server.server_launch_mode = mode
00058       else:
00059         raise Exception("Unsupported server launch mode: %s" % mode)


Member Data Documentation

server.Server.ARGS [inherited]

Definition at line 42 of file server.py.

Reimplemented from server.Server.

Definition at line 93 of file runSalome.py.

Reimplemented from server.Server.

Definition at line 96 of file runSalome.py.

Reimplemented from server.Server.

Definition at line 110 of file runSalome.py.

string server.Server.server_launch_mode = "daemon" [static, inherited]

Definition at line 37 of file server.py.


The documentation for this class was generated from the following file: