我如何做到在查询rds数据库时pymysql不挂起?

时间:2019-09-14 21:24:15

标签: python mysql amazon-web-services ubuntu pymysql

我在Amazon Web Services上设置了EC2实例。 我创建了一个RDS数据库服务,其中包含所有适当的表。 我登录到EC2实例并git pull我的代码库。 我运行使用pymysql连接到数据库的python代码,并且在发送sql请求时,程序仅挂在该行代码上。

我尝试仅在此EC2实例上运行程序。

def get_list_of_dictionaries_with_select(select_statement):
    conn = get_new_mysql_connection()
    cursor = conn.cursor(pymysql.cursors.DictCursor)
    cursor.execute(select_statement)
    return_value = cursor.fetchall()
    cursor.close()
    conn.close()
    return return_value

当我停止python时,我意识到程序卡在了cursor.execute(select_statement)代码行上。

通常,python程序不会卡住(就像我在macintosh笔记本电脑上运行时一样),但是在这种情况下,当我在云中运行它时,它会卡在cursor.execute上。

0 个答案:

没有答案