I have a python script that I'd like to run using two processes or threads. I am limited to two because I am connecting to an api/link which only has two license. I grab the license by importing their module and instantiating their class. Here are my issues:
I need to write to a sqlitedb3. I tried to share a db connection, pass it to the "worker" and have it create its own cursor but I will get stuck with a "database locked" message and it seems no matter how long I keep retrying, the lock doesnt clear. My program will spend about 5min loading data from a model, then about a minute processing data and inserting into the db. Then at the end before I move to the next model, it does a commit(). I think I can live with just creating two separate databases though
After it writes to the database, I use matplotlib to create some plots and images then save them to a file with a unique name. I kept getting "QApplication was not created in the main() thread" and "Xlib: unexpected async reply". I figure that switching from threading to multiprocess may help this
I want to make sure only two threads or processes are running at once. What is the best way to accomplish this. With threading, I was doing the following:
c1 = load_lib_get_license() c2 = load_lib_get_license() prc_list = list of models to process while (len(prc_list) > 0): if not t1.is_alive(): t1 = threading.Process(target=worker,args=(c1,db_connection,prc_list.pop(0)) t1.start() if not t2.is_alive(): t2 = threading.Process(target=worker,args=(c2,db_connection,prc_list.pop(0)) t2.start() while (t1.is_alive() and t2.is_alive(): sleep(1)