python运行程序为什么会卡住_python爬虫程序卡死

import requests

import cchardet

import sqlite3

import time

import logging

from multiprocessing.pool import ThreadPool

def execute(url):

total_time = time.time()

try:

start_time = time.time()

res = requests.get(url,timeout=1)

download_time = time.time() - start_time

start_time = time.time()

res.encoding = cchardet.detect(res.content)['encoding']

dencode_time = time.time() - start_time

except:

logging.warning(url)

pool = ThreadPool(12)

pool.map(execute,links)# links(a list):more than 60000 url of different site

上面是我用python3写的部分爬虫代码,程序总是运行到中途就会卡死,经定位发现是 res = requests.get(url,timeout=1)这句代码出了问题,因为我去掉这句代码后程序是可以欢快地跑完的。初学python,恳请大神赐教,这究竟是什么原因。links是一个list,存放了来自多个不同网站的6w多条url

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值