【问题标题】:Why does my function "hangs"为什么我的功能“挂起”
【发布时间】:2009-10-07 15:46:16
【问题描述】:
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
;

有什么想法吗?

【问题讨论】:

    标签: python mysql


    【解决方案1】:

    表上可能有一个锁阻止查询完成。

    【讨论】:

    【解决方案2】:

    尝试在执行之前将查询字符串记录到文件中。 然后当你认为它挂起时,你可以查看查询,看看它是否手动工作

    【讨论】:

    • 你的意思是在游标执行之前打印出SQL语句?好的。怀疑它与查询有什么关系。
    • 如果您知道程序挂在哪个查询上,那么您可以在 mysqlclient 中运行相同的查询,看看那里发生了什么。您可以尝试查询的变体。它看起来像一个足够简单的查询,所以挂起的原因可能很奇怪。分而治之
    【解决方案3】:

    根据您的回溯,您在执行checkTemplateBuilt 期间中断了脚本,而不是enoughPassedForTemplate

    我认为问题出在代码的不同部分;也许某处存在无限循环?也许在run 函数中?

    【讨论】:

    • 我重新编辑了我的粘贴。我不认为我会在任何地方出现无限循环。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    相关资源
    最近更新 更多