python - 线程继续在 python django 服务器中运行
问题描述
当我转到mywebiste/script时,脚本函数运行并在浏览器中呈现 json。
list = []
def script(request):
i = 0
urls = ["http://www.coden.live", "http://www.hackersvilla.xyz",]
http = urllib3.PoolManager()
threads = [threading.Thread(target=fetch_url, args=(url,)) for url in urls]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
return JsonResponse(list, safe=False)
def fetch_url(url):
http = urllib3.PoolManager()
r = http.request('GET', url)
soup = bs4.BeautifulSoup(r.data, 'html.parser')
try:
content = (soup.find("meta", {"name":"keywords"})['content'])
list.append(content)
except:
print ("No meta keywords")
我认为线程没有终止,它们也在下一个请求中继续运行。
解决方案
推荐阅读
- amazon-web-services - 同一区域内的区域之间的 AWS 延迟
- javascript - 如何在 ReasonML 绑定中包含来自相邻文件的无类型 JavaScript?
- html -
is not being displayed in the tab bar</h1> <div id="body"><p>I am a HTML beginner since we have just started working with it in school. I am encountering a problem at which i dont exactly know what I have done wrong. The line My - python-3.x - 评估函数在 x 上的导数的 Sympy 解决方案
- c++ - 包含多个 C 和 C++ 源文件的 mkoctfile
- php - 优化访问函数 laravel
- firebase - “click”事件处理程序中的错误:“ReferenceError:未定义用户”
- angular - 点击添加按钮不显示数据
- ef-core-2.1 - 如何使用 EF Core 定位 sql server 2008
- essbase - 有人可以解释以下 Essbase 代码:FIX,@relative