python捕捉线程错误_python 多线程错误

我想用多线程查找数据库,然后进行数据操作。

_list = range(19999, 100000)

pool = ThreadPool(10)

results = pool.map(main, _list)

pool.close()

pool.join()

def main(i):

print(i)

# query id, link, keywords in db

res = query('select id,link,keywords from articles where id = {}'.format(i))

但是报错如下,是数据库扛不住这样的查询还是啥意思?

19999

22000

26002

30004

34006

38008

28003

36007

32005

24001

20000

40009

42010

Traceback (most recent call last):

File "main.py", line 60, in

44011

46012

results = pool.map(main, _list)

48013

File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/pool.py", line 260, in map

52015

return self._map_async(func, iterable, mapstar, chunksize).get()

54016

File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/pool.py", line 608, in get

50014

56017

raise self._value

File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/pool.py", line 119, in worker

result = (True, func(*args, **kwds))

File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar

return list(map(*args))

File "main.py", line 17, in main

res = gao_query('select id,link,keywords from articles where id = {}'.format(i))

File "/Users/Ru/Desktop/crawl_keywords/db.py", line 13, in query_with_desc

for res in cur.fetchall():

psycopg2.ProgrammingError: no results to fetch

(py3)

query函数如下: 返回数据以字典格式,keys为colomn名。

query = partial(query_with_desc, cur)

def query_with_desc(cur, sql):

'''

cur: postgresl cursor

sql: sql statement

'''

cur.execute(sql)

index = cur.description

result = []

for res in cur.fetchall():

row = {}

for i in range(len(index)):

row[index[i][0]] = res[i]

result.append(row)

return result

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值