Python cookbook守护进程代码示例,pythoncookbook,关于python守护进程
Python cookbook守护进程代码示例,pythoncookbook,关于python守护进程
关于python守护进程的代码示例,这是来自python学习参考书《python cookbook》中的一段代码。这里需要用到python os及python sys模块方法。
在学习python的过程中,我买了很多书记,这本《python cookbook》对我在后期的帮助还是很大的。虽然书中有写好的代码,但我的个人学习习惯是,更喜欢把有特点的代码整理出来,就算是对照着敲一遍,对学习也是很有帮助的。
Python cookbook守护进程部分代码示例如下:
import osimport sysclass Daemonize: def daemonize(self): try: pid = os.fork() if pid > 0: sys.exit(0) except OSError,e: sys.stderr.write("Fork 1 has failed --> %d--[%s]\n" \ % (e.errno,e.strerror)) sys.exit(1) os.chdir('/') #detach from terminal os.setsid() #file to be created? os.umask(0) try: pid = os.fork() if pid > 0: print "Daemon process pid %d" % pid sys.exit(0) except OSError, e: sys.stderr.write("Fork 2 has failed --> %d--[%s]" \ % (e.errno, e.strerror)) sys.exit(1) sys.stdout.flush() sys.stderr.flush()#www.iplaypy.com def start_daemon(self): self.daemonize() self.run_daemon() def run_daemon(self): '''override''' passpython书籍相关文章推荐:
1、学习Python有什么好的书籍推荐?
2、Python畅销书《Python Cookbook》第三版中文版书评
编橙之家文章,
相关内容
- python自动完成扫描端口使用情况示例,python自动完成
- 如何用python方法检测UDP端口,python检测udp端口,如何用
- Python调用MySQL存储过程,获得返回值示例,pythonmysql,编橙
- Python特定文件备份方法源码示例,,Python备份文件的方
- python科学计算贝塞尔函数最大最小值,python贝塞尔,这是
- python lambda实现求素数的简短代码,pythonlambda素数,用P
- Python多进程读取文件操作方法详解,,python读取文件的操
- 用Python代码实现阿拉伯数字与罗马数字转换讲解,pyt
- Linux环境下的Python翻译工具源码,linuxpython,编橙之家P
- Python实时监控Linux cpu使用率实现方法,pythonlinux,Python监
评论关闭