for dropTime in dropTimes: for dropPercent in dropPercents: for topAverageRate in topAverageRates: for eventLengthMin in eventLengthMins: for eventLengthMax in eventLengthMaxs: for staging in stagings: options = { 'dropTime': dropTime, 'dropPercent': dropPercent, 'topAverageRate': topAverageRate, 'eventLengthMin': eventLengthMin, 'eventLengthMax': eventLengthMax, 'staging': staging, } apneaIndex = detectApneas(data, options)[0] while True: c = conn.cursor() try: t=(fileName,staging, dropTime,dropPercent,topAverageRate,eventLengthMin, eventLengthMax,apneaIndex,) print t c.execute('''INSERT INTO results (patient, staging, dropTime, dropPercent, Avgrate, minLen, maxLen, output) VALUES (?,?,?,?,?,?,?,?)''',t) conn.commit() c.close() break except: c.close() conn.close() except: