代码之家  ›  专栏  ›  技术社区  ›  Mohamed Benkedadra

PyMySQL被困在fetch_one()上,没有错误

  •  0
  • Mohamed Benkedadra  · 技术社区  · 6 年前

    你好,下面是我的代码:

    db = pymysql.connect(
        host = ....., 
        user = ....., 
        passwd = ....., 
        db = ....., 
        port = ....., 
        connect_timeout = 5 , 
        use_unicode = True, 
        charset = "utf8",
        autocommit = True,
    )
    
    c = db.cursor(pymysql.cursors.SSDictCursor)
    data  = c.execute(my_query) # for example SELECT * FROM PEOPLE
    run = True
    while run:
        ### processing in batches of 50
        batch = []
        for i in range(50):
            row = data.fetchone()
            if not row:
                 run = False 
                 break 
            row = do_something(row)
            batch += [row]
    
        do_stuff_that takes_3_minutes(batch)
    

    我的问题是,大约一个小时后,这个代码就被卡住了 data.fetchone() ,但它不会退出或显示任何错误,只是被卡住了。我知道这是因为,我在每条指令前后都添加了print语句,最后输出到控制台的是之前的print语句 fetchone()

    0 回复  |  直到 6 年前