Hi,
What is the easiest way to create a daemon process in Python? Google
says I should call fork() and other system calls manually, but is
there no os.daemon() and the like?
Regards,
--
Sakagami Hiroki 9 9114
Hello,
Sakagami Hiroki wrote:
What is the easiest way to create a daemon process in Python? Google
says I should call fork() and other system calls manually, but is
there no os.daemon() and the like?
You could try
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731>
HTH
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
Sakagami Hiroki wrote:
Hi,
What is the easiest way to create a daemon process in Python?
I find that this works great. I just pasted my copy, I think you can
find it via Google.
Eirikur
# Daemon Module - basic facilities for becoming a daemon process
# By Coy Krill
# Combines ideas from Steinar Knutsens daemonize.py and
# Jeff Kunces demonize.py
"""Facilities for Creating Python Daemons"""
import os
import time
import sys
class NullDevice:
def write(self, s):
pass
def daemonize():
if (not os.fork()):
# get our own session and fixup std[in,out,err]
os.setsid()
sys.stdin.close()
sys.stdout = NullDevice()
sys.stderr = NullDevice()
if (not os.fork()):
# hang around till adopted by init
ppid = os.getppid()
while (ppid != 1):
time.sleep(0.5)
ppid = os.getppid()
else:
# time for child to die
os._exit(0)
else:
# wait for child to die and then bail
os.wait()
sys.exit()
On Feb 21, 9:33 am, Eirikur Hallgrimsson <e...@mad.scientist.com>
wrote:
Sakagami Hiroki wrote:
What is the easiest way to create a daemon process in Python?
I've found it even easier to use the built in threading modules:
import time
t1 = time.time()
print "t_poc.py called at", t1
import threading
def im_a_thread():
time.sleep(10)
print "This is your thread speaking at", time.time()
thread = threading.Thread(target=im_a_thread)
thread.setDaemon(True)
thread.start()
t2 = time.time()
print "Time elapsed in main thread:", t2 - t1
Of course, your mileage may vary. ga******@gmail.com wrote:
On Feb 21, 9:33 am, Eirikur Hallgrimsson <e...@mad.scientist.com>
wrote:
>Sakagami Hiroki wrote:
What is the easiest way to create a daemon process in Python?
I've found it even easier to use the built in threading modules:
import time
t1 = time.time()
print "t_poc.py called at", t1
import threading
def im_a_thread():
time.sleep(10)
print "This is your thread speaking at", time.time()
thread = threading.Thread(target=im_a_thread)
thread.setDaemon(True)
thread.start()
t2 = time.time()
print "Time elapsed in main thread:", t2 - t1
Of course, your mileage may vary.
That's not a daemon process (which are used to execute 'background services'
in UNIX environments).
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
On Feb 21, 3:34 pm, Benjamin Niemann <p...@odahoda.dewrote:
That's not a daemon process (which are used to execute 'background services'
in UNIX environments).
I had not tested this by running the script directly, and in writing a
response, I found out that the entire interpreter closed when the main
thread exited (killing the daemonic thread in the process). This is
different behavior from running the script interactively, and thus my
confusion.
Thanks! ~Garrick
Thanks all,
I understood there is no shortcut function like BSD daemon(). I'll do
it manually using examples from cookbook...
On 2$B7n(B22$BF|(B, $B8aA0(B1:41, Benjamin Niemann <p...@odahoda.dewrote:
Hello,
Sakagami Hiroki wrote:
What is the easiest way to create a daemon process in Python? Google
says I should call fork() and other system calls manually, but is
there no os.daemon() and the like?
You could try
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731>
HTH
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW:http://pink.odahoda.de/
On 2007-02-22, ok******@gmail.com <ok******@gmail.comwrote:
I understood there is no shortcut function like BSD daemon(). I'll do
it manually using examples from cookbook...
Sure would be nice if somebody posted one. ;)
--
Grant Edwards grante Yow! Oh, I get it!! "The
at BEACH goes on", huh,
visi.com SONNY??
Eirikur Hallgrimsson <eh@mad.scientist.comwrote:
def daemonize():
if (not os.fork()):
# get our own session and fixup std[in,out,err]
os.setsid()
sys.stdin.close()
sys.stdout = NullDevice()
sys.stderr = NullDevice()
That doesn't close the underlying file descriptors...
Here is another method which does :-
null = os.open(os.devnull, os.O_RDWR)
os.dup2(null, sys.stdin.fileno())
os.dup2(null, sys.stdout.fileno())
os.dup2(null, sys.stderr.fileno())
os.close(null)
if (not os.fork()):
# hang around till adopted by init
ppid = os.getppid()
while (ppid != 1):
time.sleep(0.5)
ppid = os.getppid()
Why do you need hang around until adopted by init? I've never see
that in a daemonize recipe before?
else:
# time for child to die
os._exit(0)
else:
# wait for child to die and then bail
os.wait()
sys.exit()
--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rob Hunter |
last post by:
Hi all.
I want to run a Python daemon that manages a "to-do" queue. I want it
so that the daemon is always running, where its running consists of
looking at the queue to see if it has any jobs,...
|
by: bmgx |
last post by:
This is what I am trying to find out, instruction on how to create a
simple daemon on unix systems(Linux), can't find any info on usual sources..
|
by: Valia |
last post by:
hello all,
here is something i would like to do, i think this can be done with a
daemon or something like named pipe or even a daemon waiting its input
from named pipe? do not know.
please...
|
by: Bob Swerdlow |
last post by:
I've created a Python daemon that starts a bunch of BitTorrent downloader
process. Everything is working fine when I start the daemon by hand (logged
on as root). I can quit the session and see...
|
by: David Pratt |
last post by:
Hi. I am running a zope server. Zope runs 4 threads and I have a
document processing method that can require minutes to run so I do not
want to run out of threads. A solution to this is to run...
|
by: Thomas Dybdahl Ahle |
last post by:
Hi, I'm writing a program, using popen4(gnuchess),
The problem is, that gnuchess keeps running after program exit.
I know about the atexit module, but in java, you could make a process a
daemon...
|
by: Ben Finney |
last post by:
Howdy all,
For making a Python program calve off an independent daemon process of
itself, I found Carl J. Schroeder's recipe in the ASPN Python Cookbook....
|
by: paul |
last post by:
I am writing a daemon process that reads data from the serial port /
dev/ttyS0. I am using pyserial & the method for setting up a daemon
described in "Chris' Python Page"...
|
by: Johny |
last post by:
Is it possible to run a Python program as daemon?
Thanks
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |