擅长:python、mysql、java
<p>您可以使用<a href="https://docs.python.org/3/library/multiprocessing.html" rel="nofollow noreferrer">^{<cd1>}</a>或<a href="https://docs.python.org/3/library/threading.html" rel="nofollow noreferrer">^{<cd2>}</a>:</p>
<pre><code>def background_code():
while some_condition:
print("gibberish")
...
thread = threading.Thread(target=background_code, args=(), kwargs={})
thread.start()
print("pass")
...
</code></pre>
<p><code>multiprocessing</code>和{<cd2>}都有非常相似的api,使用哪种api取决于您的用例——进程和线程之间的区别并不是这个问题的关键。你可能会想要你目前正在做的工作<code>threading</code>,但是在不同的情况下,你会选择其中一种。在</p>