3

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

Community
  • 1
  • 1
Oddthinking
  • 24,359
  • 19
  • 83
  • 121

1 Answers1

2

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.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • 1
    Summarising to make sure I have it clear: os.kill(pid, 0) will NOT kill the process on POSIX platforms, but will on the TerminateProcess shiv used on Windows (since Python 2.7, which is probably why it hadn't been fixed by Paster 1.7.3). Ugh, that's an awkward situation. – Oddthinking Jun 24 '11 at 09:59
  • 1
    @Oddthinking Exactly. The name `kill` is misleading, it actually just sends a signal. However, most signals happen to be related to iterrupting/killing processes. – phihag Jun 24 '11 at 10:04