扭曲:创建ThreadPool然后进行守护进程导致无意义的挂起 [英] Twisted: Creating a ThreadPool and then daemonizing leads to uninformative hangs

查看:95
本文介绍了扭曲:创建ThreadPool然后进行守护进程导致无意义的挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Twisted中开发一个网络应用程序,其中一部分由用Django编写的Web界面组成。



我希望使用Twisted的WSGI服务器托管网络界面,并且我编写了一个有效的 tap插件以允许我使用 twistd



运行时带有 -n 标志(不要守护)的服务器一切正常,但是当删除该标志时,服务器根本不响应请求,并且没有消息记录(尽管服务器仍在运行)。



有一个关于Twisted Trac的错误,它似乎准确地描述了问题,而我的插件恰巧基于



不幸的是,这个问题尚未解决-大约一年前就提出来了。



我尝试创建 T hreadPoolService 类,扩展了 Service 并在 ThreadPool > startService 称为:

  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 服务。



至此,我已经点击了有点像砖墙。有人对我如何解决此问题有任何想法吗?

解决方案

返回 MultiService 从您的 ServiceMaker ;其中包括您的 ThreadPoolService 以及您的主要应用程序服务。组装这样的东西的API非常简单:

  multi = MultiService()
mine = TCPServer(.. 。)#您现有的应用程序服务
线程= ThreadPoolService()
mine.setServiceParent(multi)
thread.setServiceParent(multi)
返回多个

鉴于您已经在Twisted中找到了处理此令人困惑的问题的门票,因此,我很期待看到您的补丁:)。 / p>

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?

解决方案

Return a MultiService from your ServiceMaker; one that includes your ThreadPoolService as well as your main application service. The API for assembling such a thing is pretty straightforward:

multi = MultiService()
mine = TCPServer(...) # your existing application service
threads = ThreadPoolService()
mine.setServiceParent(multi)
threads.setServiceParent(multi)
return multi

Given that you've already found the ticket for dealing with this confusing issue within Twisted, I look forward to seeing your patch :).

这篇关于扭曲:创建ThreadPool然后进行守护进程导致无意义的挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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