擅长:python、mysql、java
<p>是的,Python中的每个模块都是全局的,或者更好地说,是一个单独的模块:当您执行<code>from twisted.internet import reactor</code>操作时,Python的导入机制首先检查{<cd2>},如果存在,则返回所述值;仅当它不存在时(即。,{future}第一次可能是导入一个<cdshed>模块。在</p>
<p>在单例设计模式中没有什么特别神奇的东西,尽管有时候当你迫切需要一个以上的东西时,它会被证明是有限的,而架构已经规定“只有一个”。Twisted的<a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.reactor.html" rel="noreferrer">docs</a>确认:</p>
<blockquote>
<p>New application code should prefer to
pass and accept the reactor as a
parameter where it is needed, rather
than relying on being able to import
this module to get a reference. This
simplifies unit testing and may make
it easier to one day support multiple
reactors (as a performance
enhancement), though this is not
currently possible.</p>
</blockquote>
<p>如果这对你的应用程序很重要,那么最好的办法就是为Twisted项目做出贡献,要么是人工(在一个应用程序中编写支持多个反应堆所需的微妙机制,也就是说,多个事件循环)或资助(资金将使某个人能够获得津贴,从而完成这项工作)。在</p>
<p>否则,使用单独的进程(例如,使用标准库的<code>multiprocessing</code>模块),每个进程不超过一个反应器。在</p>