Twisted:创建线程池然后守护进程会导致无信息的挂起
我正在 Twisted 中开发一个网络应用程序,其中一部分由用 Django 编写的 Web 界面组成。
我希望使用 Twisted 的 WSGI 服务器来托管 Web 界面,并且我编写了一个可用的“tap”插件来允许我使用 twistd
。
当使用 -n
标志(不守护进程)运行服务器时,一切正常,但是当删除此标志时,服务器根本不响应请求,并且没有记录任何消息(尽管服务器仍在运行)。
Twisted 的 Trac 上有一个 bug 似乎准确地描述了问题,而我的插件恰好是基于工单中引用的代码。
不幸的是,这个问题还没有得到解决 - 它是在大约一年前提出的。
我尝试创建一个 ThreadPoolService 类,它扩展了 Service 并在调用 startService 时启动给定的 ThreadPool :
class ThreadPoolService(service.Service):
def __init__(self, pool):
self.pool = pool
def startService(self):
super(ThreadPoolService, self).startService()
self.pool.start()
def stopService(self):
super(ThreadPoolService, self).stopService()
self.pool.stop()
但是,Twisted 似乎根本没有调用 startService
方法。我认为问题在于,使用“tap”插件,ServiceMaker
只能返回一个要启动的服务 - 并且属于同一应用程序的任何其他服务都不会启动。显然,我正在返回一个包含 WSGI 根的 TCPServer
服务。
在这一点上,我有点碰壁了。有人对我如何解决这个问题有任何想法吗?
I am developing a networked application in Twisted, part of which consists of a web interface written in Django.
I wish to use Twisted's WSGI server to host the web interface, and I've written a working "tap" plugin to allow me to use twistd
.
When running the server with the -n
flag (don't daemonize) everything works fine, but when this flag is removed the server doesn't respond to requests at all, and there are no messages logged (though the server is still running).
There is a bug on Twisted's Trac which seems to describe the problem exactly, and my plugin happens to be based on the code referenced in the ticket.
Unfortunately, the issue hasn't been fixed - and it was raised almost a year ago.
I have attempted to create a ThreadPoolService
class, which extends Service
and starts a given ThreadPool
when startService
is called:
class ThreadPoolService(service.Service):
def __init__(self, pool):
self.pool = pool
def startService(self):
super(ThreadPoolService, self).startService()
self.pool.start()
def stopService(self):
super(ThreadPoolService, self).stopService()
self.pool.stop()
However, Twisted doesn't seem to be calling the startService
method at all. I think the problem is that with a "tap" plugin, the ServiceMaker
can only return one service to be started - and any others belonging to the same application aren't started. Obviously, I am returning a TCPServer
service which contains the WSGI root.
At this point, I've hit somewhat of a bit of a brick wall. Does anyone have any ideas as to how I can work round this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回
MultiService
来自您的ServiceMaker
;其中包括您的 ThreadPoolService 以及您的主应用程序服务。组装这样一个东西的 API 非常简单:鉴于您已经在 Twisted 中找到了处理这个令人困惑的问题的方法,我期待看到您的补丁:)。
Return a
MultiService
from yourServiceMaker
; one that includes yourThreadPoolService
as well as your main application service. The API for assembling such a thing is pretty straightforward:Given that you've already found the ticket for dealing with this confusing issue within Twisted, I look forward to seeing your patch :).