-----Original Message-----
From: java-owner@gcc.gnu.org [mailto:java-owner@gcc.gnu.org]
On Behalf Of Ofer Nave
Sent: Friday, March 23, 2007 2:24 PM
To: java@gcc.gnu.org
Subject: My PyLucene app freezes when run as a daemon
This might be a bit off the usual topic range here, but I was
pointed to this list.
Background:
PyLucene is a GCJ-compiled version of Java Lucene integrated
with Python.
http://pylucene.osafoundation.org/
Context:
I have a PyLucene searcher application running under a
multithreaded python web server called Paste
(http://pythonpaste.org). I've added a command-line argument
to my script to run the script as a daemon based on the code
in this article:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
Problem:
When the script is run as a normal process, it works fine.
When it is run as a daemon, it freezes after about a dozen
requests. The point it's freezing at is in a call to a class
that is known to not be thread-safe, so that might be the
problem - but on the other hand, the only difference between
the good and bad scenarios is whether it's running as a
daemon, so I tend to lean towards that as my top clue.
How I Got Here:
I posted this to the PyLucene list, and was told: "You might
want to ask java@gcc.gnu.org about daemonizing a process
using libgcj and boehm-gc." So I'm giving it a shot. Does
anyone have wisdom on the care and feeding of daemonized
processes built with GCJ? Is there anything special I need
to know about?
Appendix 1 - My daemonize() Function:
# call to detach yourself from a terminal def daemonize(logfile=None):
# fork twice to sever any ties
_fork()
os.setsid()
_fork()
os.chdir(WORKDIR)
os.umask(UMASK)
# close standard I/O channels
os.close(0) # stdin
os.close(1) # stdout
os.close(2) # stderr
# redirect standard output channels to logfile
if logfile:
sys.stdout = sys.stderr = logfile
# set up SIGTERM handler for cleanup
signal(SIGTERM, _sigterm_handler)
-ofer