开发者

Paster daemon won't shut down because can't read own pid file

TL;DR version: When I ask Paster to stop-daemon, it fails to read its own file that it uses to track its process id.

Longer version:

I am running Paster (pastescript 1.7.3) on Python 2.7.1 on Windows Vista.

My first surprise comes from running a simple web-site:

>paster serve development.ini
Starting server in PID 15184.
serving on http://127.0.0.1:5000

I expected to find a paster.pid file in the same directory, but I don't. Odd. Never mind, let's make it explicit, by killing that process and starting again.

>paster serve development.ini --pid-file=my.pid
Starting server in PID 20884.
serving on http://127.0.0.1:5000

This time, it creates a file called my.pid. In another command window, I can type:

 >type my.pid
 20884

The web-site is being served successfully and Task Manager confirms there is a python process running with PID 20884.

Now, let's ask paster to report on the status of the daemon:

>paster serve development.ini --status --pid-file=my.pid
PID None in my.pid is not running

>type my.pid
20884

Odd. It claims the the PID inside my.pid is None, when it isn't.

Let's shut it down.

>paster serve --stop-daemon --pid-file=my.pid
PID in my.pid is not valid (deleting)

>type my.pid
The system cannot find the file specified.

So, it tried to read my.pid, couldn't read it, and deleted it in frustration.

Meanwhile the daemon contin开发者_如何学Goues to run.

I have to kill the paster daemon by hand, which is what @Lennart Regebro recommends in a similar, less detailed question. I want to automate this as part of my testing, so I am hoping to find a cleaner solution.

Any suggestions?


From paste script's source code(serve.py), in the PID reading method:

pid = read_pidfile(pidfile)
if pid:
    try:
        os.kill(int(pid), 0)
        return pid
    except OSError, e:
        if e.errno == errno.EPERM:
            return pid
return None

On POSIX-compatible platforms, specifying 0 as a signal just checks whether the process is alive.

However, on Windows, there is no kill system call; Python will use TerminateProcess instead. Remove the os.kill line from paster script or use a POSIX-compatible platform, like Cygwin (POSIX layer on top of Windows) or Linux.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜