擅长:python、mysql、java
<p>你做错的最大一件事,也就是最伤你的吞吐量,就是你调用<code>thread.start()</code>和<code>thread.join()</code>的方式:</p>
<pre><code>for i in range(0, 10):
thread = threading.Thread(target = current_post.post)
thread.start()
thread.join()
</code></pre>
<p>每次通过循环,您都会创建一个线程,启动它,然后等待它完成<strong>,然后再转到下一个线程。你一点也不做!</p>
<p>你应该做的是:</p>
<pre><code>threads = []
# start all of the threads
for i in range(0, 10):
thread = threading.Thread(target = current_post.post)
thread.start()
threads.append(thread)
# now wait for them all to finish
for thread in threads:
thread.join()
</code></pre>