擅长:python、mysql、java
<p>未打印任何内容的原因是<code>apply_async</code>静默失败。顺便说一句,我认为这是一种让人困惑的坏行为。您可以传递<code>error_callback</code>来处理错误。在</p>
<pre><code>def errorCallback(exception):
print(exception)
def userAsyncCall():
pool = Pool()
pool.apply_async(doSomething, [1], callback=callbackFunc, error_callback=errorCallback)
# You passed wrong arguments. doSomething() takes 1 positional argument.
# I replace [1,2] with [1].
if __name__ == "__main__":
userAsyncCall()
import time
time.sleep(3) # You need this, otherwise you will never see the output.
</code></pre>
<p>当你来的时候</p>
^{pr2}$
<p>皮克林杰罗!<del>你说得对,<code>namedtuple</code>不能从派生进程传递到回调。</del></p>
<p><del>也许这不是一种更容易接受的方式,但您可以发送<code>dict</code>作为结果,而不是{<cd3>}。</del></p>
<p>正如daghøidahl所纠正的,namedtuple可以被传递。下面这行行行得通。在</p>
<pre><code>LogEntry = namedtuple("LogEntry", ['logLev', 'msg'])
</code></pre>