python - Why time.sleep stops execution altogether? -


the following function intended run loop 20 minutes, processing sql tasks if available. avoid sql calls when there nothing process, intended sleep 5 seconds before trying process task again:

def main():     sql = 'some sql task here;'     stop_time = datetime.today() + timedelta(minutes = 20)     print('started @ ', datetime.now())     print('should stop at', stop_time)     load_more_rows = true     connectionparameters.get_conn() conn:         while load_more_rows or (datetime.now() < stop_time):             try:                 res = get_num_processed_batches(conn, sql)                 processed_batch = res > 0             except exception ex:                 log_error(repr(ex))                 processed_batch = false             if not processed_batch:                 print('sleeping @ ', datetime.now())                 time.sleep(seconds=5)             load_more_rows = processed_batch             print('finished iteration @ ', datetime.now())     print('stopped @ ', datetime.now()) 

unfortunately, instead of sleeping, waking up, , continuing process tasks until time up, stops executing altogether, shown in output:

('started @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 206652)) ('should stop at', datetime.datetime(2015, 3, 31, 17, 51, 6, 206630)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 356698)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 614349)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 638210)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 765645)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 6, 885282)) ('finished iteration @ ', datetime.datetime(2015, 3, 31, 17, 31, 7, 12109)) ('sleeping @ ', datetime.datetime(2015, 3, 31, 17, 31, 7, 13803)) 

what doing wrong?

time.sleep doesn't take keyword argument seconds:

time.sleep(5) 

i'm not sure why doesn't raise error missing required argument.

https://docs.python.org/2/library/time.html#time.sleep

>>> time.sleep(seconds=1) traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: sleep() takes no keyword arguments >>> time.sleep(1) >>> "everything fine" 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -