Paster守护程序不会关闭,因为无法读取自己的pid文件 [英] Paster daemon won't shut down because can't read own pid file

查看:85
本文介绍了Paster守护程序不会关闭,因为无法读取自己的pid文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



长版本



我正在Windows Vista的Python 2.7.1上运行Paster(粘贴脚本1.7.3)。 / p>

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

  > paster serve development.ini 
以PID 15184启动服务器。
在http://127.0.0.1:5000

服务

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

 > paster服务开发。ini--pid -file = my.pid 
在PID 20884中启动服务器。
服务于http://127.0.0.1:5000

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

 >输入my.pid 
20884

该网站已成功运行,任务管理器确认有一个运行PID 20884的python进程。



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

 >粘贴服务development.ini --status --pid-file = my.pid 
PID my.pid中没有运行

>键入my.pid
20884

奇数。它声称my.pid中的PID是 None ,否则不是。



让我们关闭它

 > paster服务--stop-daemon --pid-file = my.pid 
PID .pid无效(删除)

>键入my.pid
系统找不到指定的文件。

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



同时守护进程继续运行。



我必须手工杀死粘贴守护程序,这是@Lennart Regebro在类似但不太详细的问题中的建议。
作为测试的一部分,我想使其自动化,所以我希望找到更清洁的解决方案。



有什么建议吗?

解决方案

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

  pid = read_pidfile(pidfile)
if pid:
try:
os.kill(int (pid),0)
返回pid
,除了OSError,e:
如果e.errno == errno.EPERM:
返回pid
返回None

在与POSIX兼容的平台上,将0指定为信号只是检查该过程是否仍然存在



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


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?

解决方案

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.

这篇关于Paster守护程序不会关闭,因为无法读取自己的pid文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆