Python hangs on fetchall using MySQL connector -


i new python , mysql. writing code queries 60 different tables each containing records each second in 5 minute period. code executes every 5 minutes. few of queries can reach 1/2 mb of data in 50 kb range. running on workstation running windows 7,64-bit using mysql connector/python. testing code using powershell windows code run scheduled task. workstation has plenty of ram (8 gb). other processes running according task manager half of memory being used. performs expected processing hangs. have inserted print statements in code (i've used debugger tracing) determine hang occurs. occurring on call fetchall. below germane parts of code. caps (pseudo)constants.

mncdb = mysql.connector.connect(     option_files=env_mcg_mysql_option_file,     option_groups=env_mcg_mysql_option_group,     host=ut_get_workstation_hostname(),     database=env_mnc_database_name     ) generic_table_id in dbr_table_index:     site_table_id = dbr_site_table_names[site_id][generic_table_id]     db_cursor = mncdb.cursor()      db_command = (                   "select *"                   +" "                   +site_table_id                   +" "                   +dbr_datetime_field                   +" >= '"                   +query_start_time+"'"                   +" , "                   +dbr_datetime_field                   +" < '"                   +query_end_time+"'"                  )     try:         db_cursor.execute(db_command)         print "selected data table "+site_table_id         try:             table_info = db_cursor.fetchall()             print "extracted data table "+site_table_id         except:             print "db exception "+formatexceptioninfo()             print "fetch failed return rows..."             table_info = []             raise     except:         print "uncaught db error "+formatexceptioninfo()         raise 

. . . other processing uses data . . . db_cursor.close() mncdb.close() . . . no exceptions being raised. in separate powershell window can access data being processed code. testing data in database loaded before code executed. no processes updating database while code being tested. hanging can occur on first execution of code or after several hours of execution.

my question causing code hang on fetchall statement?

you can alleviate setting fetch size:

mncdb = mysql.connector.connect(option_files=env_mcg_mysql_option_file, option_groups=env_mcg_mysql_option_group,host=ut_get_workstation_hostname(,database=env_mnc_database_name, cursorclass = mysqldb.cursors.sscursor) 

but before this, should use mysql excuse prepared statements instead of string concatenation when building statement.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -