Does anyone have an idea why using Python's os.fork() to start a daemon process from within TextMate doesn't work? Why would I want to do this, you ask? It seems the most logical way to browse local Python documentation (via pydoc). The doc commands that already exist are great if you know exactly what you're looking for, but I still find myself starting up the doc server every now and again to go poking around. My thought was to run a command "Browse Python Documentation" or whatever from TextMate that opens a web browser to the local server. If the server isn't running then it needs to start lazily. This works great from the shell. From within TextMate the server starts fine but the process doesn't appear to be properly forked because TextMate just hangs like it's waiting. The script is attached for reference.
K
On Fri, Sep 16, at 10:31 AM, Kumar McMillan wrote:
Does anyone have an idea why using Python's os.fork() to start a daemon process from within TextMate doesn't work? Why would I want to do this, you ask? It seems the most logical way to browse local Python documentation (via pydoc). The doc commands that already exist are great if you know exactly what you're looking for, but I still find myself starting up the doc server every now and again to go poking around. My thought was to run a command "Browse Python Documentation" or whatever from TextMate that opens a web browser to the local server. If the server isn't running then it needs to start lazily. This works great from the shell. From within TextMate the server starts fine but the process doesn't appear to be properly forked because TextMate just hangs like it's waiting. The script is attached for reference.
Try the double-fork trick, that works in most of those situations. By double fork I mean the forked child process exists immediately after forking another process which does the actual work. This dis- associates the prent from the 'grandchild'. You may also have to close the open file descriptors (STDIN, STDOUT, STDERR) in the child.
Gerd
works! thanks folks. that was totally it, just had to close the standard file descriptors (good idea to have some logs too :) ). K
On 9/16/05, Gerd Knops gerti@bitart.com wrote:
On Fri, Sep 16, at 10:31 AM, Kumar McMillan wrote:
Does anyone have an idea why using Python's os.fork() to start a daemon process from within TextMate doesn't work? Why would I want to do this, you ask? It seems the most logical way to browse local Python documentation (via pydoc). The doc commands that already exist are great if you know exactly what you're looking for, but I still find myself starting up the doc server every now and again to go poking around. My thought was to run a command "Browse Python Documentation" or whatever from TextMate that opens a web browser to the local server. If the server isn't running then it needs to start lazily. This works great from the shell. From within TextMate the server starts fine but the process doesn't appear to be properly forked because TextMate just hangs like it's waiting. The script is attached for reference.
Try the double-fork trick, that works in most of those situations. By double fork I mean the forked child process exists immediately after forking another process which does the actual work. This dis- associates the prent from the 'grandchild'. You may also have to close the open file descriptors (STDIN, STDOUT, STDERR) in the child.
Gerd
Gerd Knops's double-fork trick is probably what you want (generally referred to as "daemonizing"). The reason for this is when you run a command, TextMate waits for the command to finish, and apparently when you fork it's still waiting for the forked process to finish. But double-forking (and probably closing file descriptors) should solve that issue.
On Sep 16, 2005, at 11:31 AM, Kumar McMillan wrote:
Does anyone have an idea why using Python's os.fork() to start a daemon process from within TextMate doesn't work? Why would I want to do this, you ask? It seems the most logical way to browse local Python documentation (via pydoc). The doc commands that already exist are great if you know exactly what you're looking for, but I still find myself starting up the doc server every now and again to go poking around. My thought was to run a command "Browse Python Documentation" or whatever from TextMate that opens a web browser to the local server. If the server isn't running then it needs to start lazily. This works great from the shell. From within TextMate the server starts fine but the process doesn't appear to be properly forked because TextMate just hangs like it's waiting. The script is attached for reference.
On 16/09/2005, at 20.23, Kevin Ballard wrote:
Gerd Knops's double-fork trick is probably what you want (generally referred to as "daemonizing"). The reason for this is when you run a command, TextMate waits for the command to finish, and apparently when you fork it's still waiting for the forked process to finish. But double-forking (and probably closing file descriptors) should solve that issue.
It doesn't wait for the forked process, but it does wait for the process to close stdout/err. If the process forks, the child will inherit stdout/err, and that's the problem (so it should be closed).