<blockquote>
<p>Why is that? What's the difference? Aren't they both threads?</p>
</blockquote>
<p>否,<code>LoopingCall</code>使用<a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.internet.interfaces.IReactorTime.html#callLater" rel="nofollow noreferrer">^{<cd2>}</a>;它在reactor中运行调用。在</p>
<blockquote>
<p>All my self.sendLine's in the LoopingCall are performed immediately.</p>
</blockquote>
<p>是的,应该是这样。在</p>
<blockquote>
<p>The ones in the callInThread are not.</p>
</blockquote>
<p>并不是说它们没有被执行,而是因为你从一个线程调用了reactor-API,而你从来都不允许这样做,所以你把你的程序置于一个状态,所有的东西都被彻底破坏了,永远都是</em>。以后的每个API调用都可能产生奇怪的、损坏的结果,或者没有结果,或者随机、无法解释的崩溃。在</p>
<p>你知道,多线程程序的正常工作方式;-)。在</p>
<p>重复一下:twisted中的每个API,除了<a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.internet.interfaces.IReactorThreads.html#callFromThread" rel="nofollow noreferrer">^{<cd3>}</a>(以及通过扩展调用<code>callFromThread</code>,比如<a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.internet.threads.html#blockingCallFromThread" rel="nofollow noreferrer">^{<cd5>}</a>)之外的每个API都是线程安全的。不幸的是,如果你在这两个API中设置一个单独的API,你会发现这两个API都有一个奇怪的问题。在</p>
<p>如果您有一些代码在需要调用reactor API的线程中运行,请使用<code>callFromThread</code>或{<cd5>},它将把调用分派到reactor线程,在那里所有的工作都应该顺利。但是,对于定时调用之类的东西,实际上根本不需要使用线程,它们会不必要地使程序复杂化。在</p>