python - 为什么我的函数 "hangs"

标签 python mysql

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 - 为什么我的函数 "hangs",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1532474/

相关文章:

mysql - 如果月份相同,PHP Mysql如何在相同的行中获得结果

php - 问一下php summarize 01 + 01 = 02

python - 当 Python 套接字连接失败时正确设置超时

python - 将 Django 智能感知添加到 Pycharm 中?

MySqlException : Fatal error encountered during command execution . Asp.net Core

mysql - 我需要一个 SQL 查询,它根据 C 列中是否存在字符串从 A 列或 B 列中进行选择

Mysql数据库表结构

python - 如何在 MacOS 上正确卸载 numpy?

python - 在 Bokeh 中更新 ColorBar

python - 到同一 DF 中最近点的距离