免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2584 | 回复: 2
打印 上一主题 下一主题

【已解决】请给我看个错误 [复制链接]

论坛徽章:
13
CU大牛徽章
日期:2013-03-14 14:14:082016科比退役纪念章
日期:2016-07-22 11:15:35数据库技术版块每日发帖之星
日期:2016-05-27 06:20:002015亚冠之吉达阿赫利
日期:2015-08-05 10:06:542015年亚洲杯之韩国
日期:2015-04-01 16:05:42双鱼座
日期:2014-11-13 11:04:24丑牛
日期:2014-07-25 17:29:54子鼠
日期:2014-04-25 12:25:45丑牛
日期:2014-04-17 08:35:48巨蟹座
日期:2014-04-16 16:50:05CU大牛徽章
日期:2013-03-14 14:14:29CU大牛徽章
日期:2013-03-14 14:14:26
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-06-30 13:32 |只看该作者 |倒序浏览
本帖最后由 hmchzb19 于 2014-07-01 13:34 编辑

Exception in thread Thread-10 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
  File "./url_fetch_threaded_part2.py", line 44, in run
  File "/usr/lib64/python2.6/Queue.py", line 168, in get
  File "/usr/lib64/python2.6/threading.py", line 232, in wait
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

代码如下

  1. #! /usr/bin/env python
  2. import Queue
  3. import threading
  4. import urllib2
  5. import time
  6. from BeautifulSoup import BeautifulSoup

  7. hosts = ["http://yahoo.com", "http://google.com", "http://amazon.com",
  8.         "http://ibm.com", "http://apple.com"]

  9. queue = Queue.Queue()
  10. out_queue = Queue.Queue()

  11. class ThreadUrl(threading.Thread):
  12.     """Threaded Url Grab"""
  13.     def __init__(self, queue, out_queue):
  14.         threading.Thread.__init__(self)
  15.         self.queue = queue
  16.         self.out_queue = out_queue

  17.     def run(self):
  18.         while True:
  19.             #grabs host from queue
  20.             host = self.queue.get()

  21.             #grabs urls of hosts and then grabs chunk of webpage
  22.             url = urllib2.urlopen(host)
  23.             chunk = url.read()

  24.             #place chunk into out queue
  25.             self.out_queue.put(chunk)

  26.             #signals to queue job is done
  27.             self.queue.task_done()

  28. class DatamineThread(threading.Thread):
  29.     """Threaded Url Grab"""
  30.     def __init__(self, out_queue):
  31.         threading.Thread.__init__(self)
  32.         self.out_queue=out_queue
  33.     def run(self):
  34.         while True:
  35.             #grabs host from queue
  36.             chunk = self.out_queue.get()
  37.             #parse the chunk
  38.             soup = BeautifulSoup(chunk)
  39.             print soup.findAll(['title'])

  40.             #signals to queue job is done
  41.             self.out_queue.task_done()

  42. start = time.time()
  43. def main():

  44.     #populate queue with data
  45.     for host in hosts:
  46.         queue.put(host)
  47.     #spawn a pool of threads, and pass them queue instance
  48.     for i in range(5):
  49.         t = ThreadUrl(queue, out_queue)
  50.         t.setDaemon(True)
  51.         t.start()

  52.     for i in range(5):
  53.         dt = DatamineThread(out_queue)
  54.         dt.setDaemon(True)
  55.         dt.start()


  56.     #wait on the queue until everything has been processed
  57.     queue.join()
  58.     out_queue.join()

  59. main()
  60. print "Elapsed Time: %s" % (time.time() - start)
复制代码

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 10:01:44
2 [报告]
发表于 2014-06-30 18:58 |只看该作者
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

这句话已经很明显了,空类型不是可调用的。 肯定是你传递了一个可执行的类型,结果这个参数是None。

论坛徽章:
13
CU大牛徽章
日期:2013-03-14 14:14:082016科比退役纪念章
日期:2016-07-22 11:15:35数据库技术版块每日发帖之星
日期:2016-05-27 06:20:002015亚冠之吉达阿赫利
日期:2015-08-05 10:06:542015年亚洲杯之韩国
日期:2015-04-01 16:05:42双鱼座
日期:2014-11-13 11:04:24丑牛
日期:2014-07-25 17:29:54子鼠
日期:2014-04-25 12:25:45丑牛
日期:2014-04-17 08:35:48巨蟹座
日期:2014-04-16 16:50:05CU大牛徽章
日期:2013-03-14 14:14:29CU大牛徽章
日期:2013-03-14 14:14:26
3 [报告]
发表于 2014-06-30 21:28 |只看该作者
也就是说out_queue是None,但是我没有看出来为啥是空的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP