I’m trying to write a program that moves a highlight through the phrases of a text at specified times. My program works for a while but then stops. How far it gets, and what error it reports, varies from run to run, and I don’t know what’s causing this. Perhaps it has something to do with my use of threading.Timer. I’ve attached a fairly minimal version of the program that demonstrates the problem and below I’ve copied the different outputs from three different runs of this sample program. I’d be grateful if someone could tell me what I’m doing wrong. I’m using wxPython 2.8.11.0 on Python 2.7 and Windows 7.
Thanks,
Patrick Maher
Results from three successive runs of advancephrase.py:
FIRST:
selected phrase 0
unseleted phrase 0
selected phrase 1
unseleted phrase 1
selected phrase 2
[Windows then popped up a window saying the program had stopped working.]
SECOND:
selected phrase 0
unseleted phrase 0
selected phrase 1
unseleted phrase 1
selected phrase 2
Exception in thread Thread-3:
Traceback (most recent call last):
File “C:\Python27\lib\threading.py”, line 530, in __bootstrap_inner
self.run()
File “C:\Python27\lib\threading.py”, line 734, in run
self.function(*self.args, **self.kwargs)
File “C:\Monceau\test\advancephrase.py”, line 46, in
timer = threading.Timer(duration/1000.0,lambda: self.advanceselection(None))
File “C:\Monceau\test\advancephrase.py”, line 40, in advanceselection
self.SetStyle(self.ranges[self.phrasenum-1], self.normalstyle) #Unselect previously selected phrase
File “C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\richtext.py”, line 2531, in SetStyle
return _richtext.RichTextCtrl_SetStyle(*args, **kwargs)
PyAssertionError: C++ assertion “uiIndex < m_nCount” failed at …\include\wx/dynarray.h(813) in w
xBaseArrayInt::Item()
THIRD:
selected phrase 0
unseleted phrase 0
selected phrase 1
unseleted phrase 1
selected phrase 2
unseleted phrase 2
selected phrase 3
unseleted phrase 3
selected phrase 4
unseleted phrase 4
Unhandled exception in thread started by <bound method _Timer.__bootstrap of <_Timer(Thread-5, stopp
ed 18932)>>
Traceback (most recent call last):
File “C:\Python27\lib\threading.py”, line 503, in __bootstrap
self.__bootstrap_inner()
File “C:\Python27\lib\threading.py”, line 543, in __bootstrap_inner
(self.name, _format_exc()))
File “C:\Python27\lib\traceback.py”, line 144, in format_exception
list = list + format_exception_only(etype, value)
TypeError: ‘list’ object is not callable
advancephrase.py (3.14 KB)