mirror of
				https://github.com/samuelclay/NewsBlur.git
				synced 2025-10-31 08:41:36 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			No EOL
		
	
	
		
			638 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			No EOL
		
	
	
		
			638 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os
 | |
| import errno
 | |
| 
 | |
| def daemonize():
 | |
|     """
 | |
|     Detach from the terminal and continue as a daemon.
 | |
|     """
 | |
|     # swiped from twisted/scripts/twistd.py
 | |
|     # See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
 | |
|     if os.fork():   # launch child and...
 | |
|         os._exit(0) # kill off parent
 | |
|     os.setsid()
 | |
|     if os.fork():   # launch child and...
 | |
|         os._exit(0) # kill off parent again.
 | |
|     os.umask(077)
 | |
|     null = os.open("/dev/null", os.O_RDWR)
 | |
|     for i in range(3):
 | |
|         try:
 | |
|             os.dup2(null, i)
 | |
|         except OSError, e:
 | |
|             if e.errno != errno.EBADF:
 | |
|                 raise
 | |
|     os.close(null) | 
