multithreading - Python separate threads are killing the whole program -
so wrote script:
def schedule_setup(): # kill old threads should exist global active active = false time.sleep(3) active = true global threadlist threadlist = [] try: sql = "select time_to_run time_table" cursor.execute(sql) results = cursor.fetchall() row in results: #row[0].strftime('%h:%m') t = threading.thread(target=th,args=(row[0].strftime('%h:%m'),)) t.start() threadlist.append(t) # join threads main memory #for count in threadlist: #count.join() sql = "update motor set update_schedule = 0" try: cursor.execute(sql) # commit changes in database db.commit() except: # rollback in case there error print "no worky" db.rollback() except: print "error: unable table data"
it takes times setup on sql , creates scheduled event action. put in beginning thread "killer" active threads if ever call thread again because times have been updated can kill old ones , replace them new. works how want to, action called whole program crashes... here code calls:
def th(run_time): global active schedule.every().day.at(run_time).do(run_motor) while active == true: schedule.run_pending() time.sleep(1)
see how thread checks every second? threads killed when try create new ones, when "run_motor" gets called, afterwords main program supposed loop indefinitely crashes , other threads still going strange me.
you can't sanely kill thread. instead of killing thread, code thread what, , what, want do. way, you'll have no need kill it.
if share car 2 other people , car isn't in driveway, can't kill person driving car. free car use, won't in driveway because killed driver before had chance put back. instead, call them , tell them bring car , let them release car when they're done.
Comments
Post a Comment