擅长:python、mysql、java
<blockquote>
<p>Currently I have a function (view) that go over each URL to get the
information, and update the DB.</p>
</blockquote>
<p>这意味着响应时间对您来说无关紧要,如果您的响应时间减少了4(使用4个子进程/线程),那么您可以在前台执行,而不是在后台(异步)执行。如果是这种情况,您可以简单地将示例代码放在视图中。就像</p>
<pre><code>from multiprocessing import Pool
def updateDB(ip):
code goes here...
def my_view(request):
pool = Pool(processes=4) # process per core
pool.map(updateDB, ip)
return HttpResponse("SUCCESS")
</code></pre>
<p>但是,如果你想在后台异步完成,那么你应该使用芹菜或者遵循@BasicWolf的建议之一。</p>