My PyLucene app freezes when run as a daemon

Ofer Nave
Fri Mar 23 21:23:00 GMT 2007

This might be a bit off the usual topic range here, but I was pointed to
this list.


PyLucene is a GCJ-compiled version of Java Lucene integrated with Python.


I have a PyLucene searcher application running under a multithreaded python
web server called Paste (  I've added a command-line
argument to my script to run the script as a daemon based on the code in
this article:


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 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

    # 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)


More information about the Java mailing list