擅长:python、mysql、java
<p>如果主回路是gobject.MainLoop()是使用gobject线程的更好方法。
如果Qt—使用Qt。在</p>
<p>此修饰符使用<code>gobject.idle_add</code>使函数异步,但没有回调</p>
<pre><code>def async(func):
"""Make a function mainloop friendly. the function will be called at the
next mainloop idle state."""
def new_function(*args, **kwargs):
def async_function():
func(*args, **kwargs)
return False
gobject.idle_add(async_function)
return new_function
</code></pre>
<p>在函数中实现调用回调,而不是<code>return</code>,或者像<code>def background(callback):...</code>那样将其传递给decorator</p>