I’ve got an asynchronous taskchain to perform tasks in parallel with the application thread, but if a task raise an exception, it is simply restarted instead of being aborted or the whole application stopped.
Here is a simple example:
#!/usr/bin/env python
from direct.showbase.ShowBase import ShowBase
def processTask(task):
print("Hello")
wrong.value = 1
print("Goodbye")
return task.done
base = ShowBase()
base.taskMgr.setupTaskChain("chain",
numThreads = 1,
tickClock = False,
threadPriority = None,
frameBudget = -1,
frameSync = False,
timeslicePriority = True)
process_task = base.taskMgr.add(processTask, 'ProcessTask', taskChain="chain")
base.run()
The (truncated) log is :
Hello
:thread(error): Exception occurred within Thread TaskManager_chain_0
Traceback (most recent call last):
File "tests/test_task.py", line 7, in processTask
wrong.value = 1
NameError: name 'wrong' is not defined
:task(error): Exception occurred in PythonTask ProcessTask
Hello
:thread(error): Exception occurred within Thread TaskManager_chain_0
Traceback (most recent call last):
File "tests/test_task.py", line 7, in processTask
wrong.value = 1
NameError: name 'wrong' is not defined
:task(error): Exception occurred in PythonTask ProcessTask
Hello
:thread(error): Exception occurred within Thread TaskManager_chain_0
Traceback (most recent call last):
File "tests/test_task.py", line 7, in processTask
wrong.value = 1
NameError: name 'wrong' is not defined
:task(error): Exception occurred in PythonTask ProcessTask
The workaround is to wrap the actual task code with a try: except and use sys.exit() to stop the application but it’s rather ugly to say the less.
The problem is identical using Python2 or Python3