Note that there are some explanatory texts on larger screens.

plurals
  1. POPython separate threads are killing the whole program
    primarykey
    data
    text
    <p>So I wrote this script:</p> <pre><code>def schedule_setup(): # KILL OLD THREADS SHOULD THEY EXIST global active active = False time.sleep(3) active = True global threadlist threadlist = [] try: sql = "SELECT TIME_TO_RUN FROM time_table" cursor.execute(sql) results = cursor.fetchall() for 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 all threads to main memory #for count in threadlist: #count.join() sql = "UPDATE motor SET UPDATE_SCHEDULE = 0" try: cursor.execute(sql) # commit the changes in database db.commit() except: # Rollback in case there is any error print "no worky" db.rollback() except: print "Error: UNABLE TO GET TABLE DATA" </code></pre> <p>It takes times setup on sql and creates a scheduled event to do an action. I put in the beginning the thread "killer" for all active threads so that if I ever call this thread again because times have been updated it can kill old ones and replace them with the new. It all works how I want it to, but as soon as the action is called the whole program crashes... here is the code it calls:</p> <pre><code>def th(run_time): global active schedule.every().day.at(run_time).do(run_motor) while active == True: schedule.run_pending() time.sleep(1) </code></pre> <p>see how the thread checks every second? So threads are killed when I try to create new ones, but when "run_motor" gets called, afterwords the main program that is supposed to loop indefinitely crashes and sometimes other threads are still going so it is all very strange to me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload