Python Daemon守护进程的代码实例,python守护进程,编橙之家Python之家
Python Daemon守护进程的代码实例,python守护进程,编橙之家Python之家
编橙之家Python之家本篇文章为python Daemon实现守护进程用法,并用实例代码分析了Python Daemon进程操作的相关技巧,有需求的朋友们可以借鉴参考并改进后再使用。
def createDaemon(): import os # create - fork 1 try: if os.fork() > 0: os._exit(0) # exit father… except OSError, error: print ‘fork #1 failed: %d (%s)’ % (error.errno, error.strerror) os._exit(1) # it separates the son from the father os.chdir(’/') os.setsid() os.umask(0) # create - fork 2 try: pid = os.fork() if pid > 0: print ‘Daemon PID %d’ % pid os._exit(0) except OSError, error: print ‘fork #2 failed: %d (%s)’ % (error.errno, error.strerror) os._exit(1) funzioneDemo() # function demo#www.iplaypy.com def funzioneDemo(): import time fd = open('/tmp/demone.log', 'w') while True: fd.write(time.ctime()+'\n') fd.flush() time.sleep(2) fd.close() if __name__ == '__main__': createDaemon()
编橙之家文章,
相关内容
- Python清空文件夹及内容的方法源码,,编橙之家Python之家
- Python实现自动扫雷游戏的方法源码,python自动扫雷,编橙
- Python实现的几个常见的排序算法,python排序算法,编橙之
- 用Python杀进程的方法之windows平台示例详解,python示例
- 用Python求素数的快速算法源码示例,python素数,本篇文章
- Python select简单实现socket服务器的方法,pythonsocket,编橙
- Python MySQLdb模块简单封装的方法源码,pythonmysqldb,日常工
- Python Google talk聊天机器人源码,python聊天机器人,Pytho
- Python语言判断输入的是否是回文数的方法,,Python语言如
- Python localtime()方法计算今天是一年中第几周,pythonloc
评论关闭