Paster 守护进程不会关闭,因为无法读取自己的 pid 文件

发布于 2024-11-17 05:20:57 字数 1392 浏览 2 评论 0原文

TL;DR 版本:当我要求 Paster 停止守护进程时,它无法读取自己用来跟踪其进程 ID 的文件。

较长版本

我在 Windows Vista 上的 Python 2.7.1 上运行 Paster (pastescript 1.7.3)。

我的第一个惊喜来自于运行一个简单的网站:

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

我希望在同一目录中找到一个 Paster.pid 文件,但我没有。奇怪的。没关系,让我们通过终止该进程并重新开始来明确说明。

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

这次,它创建了一个名为 my.pid 的文件。在另一个命令窗口中,我可以输入:

 >type my.pid
 20884

网站正在成功提供服务,任务管理器确认有一个 PID 为 20884 的 python 进程正在运行。

现在,让我们让 Paster 报告守护进程的状态:

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

>type my.pid
20884

Odd。它声称 my.pid 中的 PID 为 None,但事实并非如此。

我们把它关掉吧。

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

因此,它尝试读取 my.pid,但无法读取,并沮丧地将其删除。

与此同时,守护进程继续运行。

我必须手动杀死 Paster 守护进程,这是 @Lennart Regebro 在 类似的、不太详细的问题中建议的。 我想将其自动化作为测试的一部分,所以我希望找到一个更干净的解决方案。

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷雨优美回忆 2024-11-24 05:20:57

从粘贴脚本的源代码(serve.py)中,在PID读取方法中:

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

在POSIX兼容平台上,指定0作为信号仅检查进程是否处于活动状态

然而,在 Windows 上,没有 kill 系统调用; Python 将使用 TerminateProcess 代替。从粘贴脚本中删除 os.kill 行或使用 POSIX 兼容平台,例如 Cygwin(Windows 之上的 POSIX 层)或 Linux。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文