当前位置: 首页>>代码示例>>Python>>正文


Python Trace.trace_fn方法代码示例

本文整理汇总了Python中Trace.trace_fn方法的典型用法代码示例。如果您正苦于以下问题:Python Trace.trace_fn方法的具体用法?Python Trace.trace_fn怎么用?Python Trace.trace_fn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Trace的用法示例。


在下文中一共展示了Trace.trace_fn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import Trace [as 别名]
# 或者: from Trace import trace_fn [as 别名]
 def start(self, name, program, *args, **kargs):
     tracedir = kargs.get("trace_dir")
     appdir = kargs.get("app_dir")
     pidfile = joinpths(tracedir, name + ".pid")
     stderr = joinpths(tracedir, name + ".stderr")
     stdout = joinpths(tracedir, name + ".stdout")
     tracefn = Trace.trace_fn(tracedir, name)
     tracefn = Trace.touch_trace(tracedir, name)
     runtrace = Trace.Trace(tracefn)
     runtrace.trace(RUN, RUN_TYPE)
     runtrace.trace(PID_FN, pidfile)
     runtrace.trace(STDERR_FN, stderr)
     runtrace.trace(STDOUT_FN, stdout)
     #fork to get daemon out
     pid = os.fork()
     if(pid == 0):
         os.setsid()
         pid = os.fork()
         #fork to get daemon out - this time under init control
         #and now fully detached (no shell possible)
         if(pid == 0):
             #move to where application should be
             os.chdir(appdir)
             #close other fds
             limits = resource.getrlimit(resource.RLIMIT_NOFILE)
             mkfd = limits[1]
             if(mkfd == resource.RLIM_INFINITY):
                 mkfd = MAXFD
             for fd in range(0, mkfd):
                 try:
                     os.close(fd)
                 except OSError:
                     #not open, thats ok
                     pass
             #now adjust stderr and stdout
             stdoh = open(stdout, "w")
             stdeh = open(stderr, "w")
             os.dup2(stdoh.fileno(), sys.stdout.fileno())
             os.dup2(stdeh.fileno(), sys.stderr.fileno())
             #now exec...
             #the arguments to the child process should
             #start with the name of the command being run
             actualargs = [program] + list(args)
             os.execlp(program, *actualargs)
         else:
             #write out the child pid
             contents = str(pid) + "\n"
             write_file(pidfile, contents)
             #not exit or sys.exit, this is recommended
             #since it will do the right cleanups that we want
             #not calling any atexit functions, which would
             #be bad right now
             os._exit(0)
     else:
         return tracefn
开发者ID:mmm,项目名称:Openstack-Devstack2,代码行数:57,代码来源:Foreground.py

示例2: stop

# 需要导入模块: import Trace [as 别名]
# 或者: from Trace import trace_fn [as 别名]
 def stop(self, name, *args, **kargs):
     rootdir = kargs.get("trace_dir")
     pidfile = joinpths(rootdir, name + ".pid")
     stderr = joinpths(rootdir, name + ".stderr")
     stdout = joinpths(rootdir, name + ".stdout")
     tfname = Trace.trace_fn(rootdir, name)
     if(isfile(pidfile) and isfile(tfname)):
         pid = int(load_file(pidfile).strip())
         killed = False
         lastmsg = ""
         attempts = 1
         for attempt in range(0, MAX_KILL_TRY):
             try:
                 os.kill(pid, signal.SIGKILL)
                 attempts += 1
             except OSError as (ec, msg):
                 if(ec == errno.ESRCH):
                     killed = True
                     break
                 else:
                     lastmsg = msg
                     time.sleep(SLEEP_TIME)
         #trash the files
         if(killed):
             LOG.info("Killed pid %s in %s attempts" % (str(pid), str(attempts)))
             LOG.info("Removing pid file %s" % (pidfile))
             unlink(pidfile)
             LOG.info("Removing stderr file %s" % (stderr))
             unlink(stderr)
             LOG.info("Removing stdout file %s" % (stdout))
             unlink(stdout)
             LOG.info("Removing %s trace file %s" % (name, tfname))
             unlink(tfname)
         else:
             msg = "Could not stop program named %s after %s attempts - [%s]" % (name, MAX_KILL_TRY, lastmsg)
             raise StopException(msg)
开发者ID:mmm,项目名称:Openstack-Devstack2,代码行数:38,代码来源:Foreground.py


注:本文中的Trace.trace_fn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。