I have any issue with wxpython's textctrl and threading. Would appreciate any help in resolving this issue.
My program processes files, as and when each file is processed it is listed within the textctrl as being completed. When working with just a few files the textctrl is responsive and displays itself immediately and does not disappear. Even if these files are large. Did a test on a 700mb file and textctrl worked perfectly.
The problem occurs when workin on many files, say 20+ for exmaple. Under these circumstances the textctrl disappears for 6 or 7 seconds, then reappears and works as normal.
I have tried normal threading, daemon threading etc.. Also tried using .join() which made things even worse. I'm wondering if this is just because my program is very processor intensive, or if I'm just doing something wrong.
My thread line of code is listed below. So far this is by far the fastest method, just not good enough for my purposes. Thanks in advance, Clinton.
def Worker(self, e, _file):
match = ''
with open(_file, 'r') as f:
data = f.read()
for char in data:
if char in self.key:
match += chr(self.key.index(char))
open(_file, 'w').close()
with open(_file, 'w') as f:
f.write(match)
wx.CallAfter(self.ListFilesEncrypt, e, _file)
if __name__ == '__main__':
for _file in self.file2process:
self.filenum += 1
Thread(target=self.Worker, args=(e, _file,)).start()
Update the GUI using thread-safe methods. In wxPython, there are 3:
You should also take a look the wxPython wiki for information on wxPython and threading:
I also wrote a tutorial on the topic:
UPDATE: Here is a simple example that creates 40 threads and "processes" 40 made up files. It updates the display when each thread is done. However, I do not see the issue you speak of.
I am running on Windows 7 using Python 2.6 with wxPython 2.8.12.1