multithreading - PySide timers/threading crash -
i've written pyside windows application uses libvlc show video, log keystrokes, , write aggregated information keystrokes file. i'm experiencing 2 bugs causing application crash (other question here -> https://stackoverflow.com/questions/18326943/pyside-qlistwidget-crash).
the application writes keystroke file @ every 5 minute interval on video. users can change playback speed, 5 minute interval may take more or less 5 minutes; it's not controlled timer.
the video continues playing while file written, i've created object inheriting threading.thread file creation - intervalfile. information file written passed in constructor; intervalfile doesn't access parent (the main qwidget) @ all. threading object use in app. there no timer declared anywhere.
intermittently, application crash , i'll following message: "qobject::killtimers: timers cannot stopped thread".
the code creates intervalfile (part of customwidget, inherited qwidget):
def dointervalchange(self): ... ifile = intervalfile(5, filepath, dbpath) # db sqlite, new connection created within intervalfile ifile.start() #end of def
dointervalchange called within qwidget using signal. intervalfile is:
class intervalfile(threading.thread): def __init__(self, interval, filepath, dbpath): # declaration of variables threading.thread.__init__(self) def run(self): shutil.copy('db.local', self.dbpath) # because db still being used in main qwidget self.localdb = local(self.dbpath) # creates connection sqlite db, sql within object make db calls easier # query db keystroke data # write file self.localdb.close() self.localdb = none os.remove(self.dbpath) # don't need copy anymore
when ifile.start() commented out, don't see killtimers crash. suggestions? note crash seems random; can use app (just continuely pressing same keystroke on , over) hour without crashing, it's within first couple of intervals. because of difficulty reproducing crashes, think these lines of code issue, i'm not 100% sure.
i'm pretty sure need hold reference thread object. when dointervalchange()
method finishes, nothing holding reference thread object (ifile) more , can garbage collected. presumably why crash happens randomly (if thread finishes it's task before object garbage collected, don't have problem).
not sure creating qtimers, i'm won't affect proposed solution!
so in dointervalchange() save reference ifile in list, , periodically clean list when threads have finished execution. have @ idea (and if better way clean threads shows in post, implement that!): is there more elegant way clean thread references in python? have worry them?
Comments
Post a Comment