multithreading - Python: Threading with wxPython -
i new threading , trying grip of. creating thread handle long running process separate main thread (which handles graphical user process). otherwise, have blocking gui not nice.
the process keeps repeating itself, code in thread runs again instead of stopping alldone function, doesn't make sense me.
no matter route code takes within run portion (whether finddomains function, searchandscrape function, or emailformat function), end @ emailformat function calling alldone function of myclass object of gui(called windowclass):
class windowclass(wx.frame): def __init__(self, parent, title): super(windowclass, self).__init__(parent, title=title, size=(500, 364), style=wx.default_frame_style & ~wx.maximize_box ^ wx.resize_border) self.setbackgroundcolour('white') self.basicgui() def alldone(self, event): myclass.worker.stop() time.sleep(2) dlg = wx.messagebox("all done!", "ask alfred", wx.ok | wx.icon_information) if dlg.showmodal() == wx.id_ok: while true: try: os.unlink(self.fpath) os.rename(self.temp, self.fpath) self.destroy() except windowserror: myclass.closeit(self) break
to keep brevity , not post 500 lines of code, here thread class:
class openexcel(thread): def __init__(self, file): thread.__init__(self) super(openexcel, self).__init__() self._stop=event() self.file = file self._want_abort = 0 self.start() self._stop=false def run(self): rbook=xlrd.open_workbook(self.file) sheet = rbook.sheet_by_index(0) numrows = (sheet.nrows) wbook = copy(rbook) skipnorbertvalue=myclass.skipnorbert.ischecked() searchrow=numrows row in range(numrows): valueone=sheet.cell_value(row, 2) if valueone =="": searchrow=row break scraperow = numrows row in range(numrows): valuetwo=sheet.cell_value(row, 3) if valuetwo == "": scraperow=row break elif valuetwo=="over search limit": scraperow=row break if searchrow < numrows: while true: try: browserindex=myclass.currentbrowser search=startsearch(self.file) search.finddomains(browserindex, searchrow, numrows, sheet, wbook, self.file) except attributeerror: myclass.nobrowser(self) elif skipnorbertvalue==false , scraperow < numrows: try: browserindex=myclass.currentbrowser search=startsearch(self.file) search.searchandscrape(browserindex, scraperow, numrows, wbook, self.file) except attributeerror: myclass.nobrowser(self) else: checkformat=emailformat() checkformat.possibleemail(numrows, sheet, wbook, self.file) def abort(self): self._want_abort = 1 def stop(self): self._stop=true
Comments
Post a Comment