为什么我的函数“卡住”了
def retCursor():
host = "localhost"
user = "disappearedng"
db = "gupan_crawling3"
conn = MySQLdb.connect( host=host, user=user, passwd=passwd, db=db)
cursor = conn.cursor()
return cursor
singleCur = retCursor()
def checkTemplateBuilt(netlocH):
"""Used by crawler specifically, this check directly whether template has been built"""
singleCur.execute( """SELECT templateBuilt FROM templateEnough WHERE netloc=%s""", [ netlocH])
r = singleCur.fetchone()
if r:
if bool( r[0]):
return True
return False
大家好,我现在在用MySQLdb。出于某种原因,我的应用程序运行大约30分钟后就完全停止了。看起来是这个功能在阻碍我。(我不知道是什么原因)
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/mount/950gb/gupan5/disappearedng_temp/code_temp_NEWBRANCH/gupan5-yahoo/crawling/templateCrawling/TemplateCrawler/crawler/crawler.py", line 117, in run
self.get_check_put()
File "/mount/950gb/gupan5/disappearedng_temp/code_temp_NEWBRANCH/gupan5-yahoo/crawling/templateCrawling/TemplateCrawler/crawler/crawler.py", line 66, in get_check_put
if not self.checkLinkCrawlability(linkS, priority):
File "/mount/950gb/gupan5/disappearedng_temp/code_temp_NEWBRANCH/gupan5-yahoo/crawling/templateCrawling/TemplateCrawler/crawler/crawler.py", line 53, in checkLinkCrawlability
if checkTemplateBuilt( getNetLoc( link)):
File "/mount/950gb/gupan5/disappearedng_temp/code_temp_NEWBRANCH/gupan5-yahoo/crawling/templateCrawling/TemplateCrawler/publicapi/publicfunc.py", line 71, in checkTemplateBuilt
singleCur.execute( """SELECT templateBuilt FROM templateEnough WHERE netloc=%s""", [ netlocH])
File "/var/lib/python-support/python2.6/MySQLdb/cursors.py", line 153, in execute
r = self._query(query)
KeyboardInterrupt
顺便说一下,这是表格:
CREATE TABLE templateEnough(
`netloc` INT(32) unsigned NOT NULL,
`count` SMALLINT(32) unsigned NOT NULL,
`templateBuilt` TINYINT(1) unsigned DEFAULT 0 NOT NULL,
PRIMARY KEY ( netloc )
) ENGINE=MEMORY DEFAULT CHARSET=utf8
;
有什么想法吗?
3 个回答
0
根据你的错误信息,你是在执行 checkTemplateBuilt
这个部分的时候中断了脚本,而不是 enoughPassedForTemplate
。
我觉得问题可能出在代码的其他地方;也许某个地方有个无限循环?可能是在 run
函数里?
1
在你执行查询之前,试着把查询字符串记录到一个文件里。这样,当你觉得程序卡住的时候,就可以查看这个查询,看看手动执行时是否能正常工作。
1
可能有一个锁在这个表上,导致查询无法完成。