0
我有一個小問題,在攪拌機遊戲引擎中有一個多線程的python腳本。 它工作正常,但是當我停止遊戲時,它會引發一些異常,有時會崩潰。Python多線程 - 在Blender中關閉線程
from bge import logic
import time
from threading import Thread
def init():
if not hasattr(logic, 'init'):
logic.init = 0
logic.thread = new()
logic.thread.start()
logic.thread.restart()
class new(Thread):
def __init__(self):
self.Thread = Thread
self.Thread.__init__(self)
def run(self):
number = 0
while 1:
number += 1
print(number)
try:
main()
time.sleep(0.1)
except:
break
def restart(self):
self.Thread.__init__(self)
def main(): #this part isn't important now ...
cam = bge.logic.getCurrentScene().active_camera
obj = bge.logic.getCurrentController().owner
obj.worldPosition.x = cam.worldPosition.x
obj.worldPosition.y = cam.worldPosition.y
控制檯寫道:
Unhandled exception in thread started by <bound method new._bootstrap of <new(Th
read-80, initial)>>
Traceback (most recent call last):
File "C:\Program Files (x86)\Blender Foundation\Blender\2.64\python\lib\thread
ing.py", line 709, in _bootstrap
self._bootstrap_inner()
File "C:\Program Files (x86)\Blender Foundation\Blender\2.64\python\lib\thread
ing.py", line 784, in _bootstrap_inner
with _active_limbo_lock:
AttributeError: __exit__
我會很高興,如果有人能找到什麼地方錯了。 謝謝
你能否在你的問題中包括例外情況?另外,'self.Thread = Thread'看起來很奇怪。這條線是什麼? – phihag 2013-02-10 18:05:25
當然, 由> Traceback(最近調用最後一次): 文件「C:\ Program Files(x86) \ Blender Foundation \ Blender \ 2.64 \ python \ lib \ thread ing.py「,第709行,在_bootstrap self._bootstrap_inner() 文件」C:\ Program Files(x86)\ Blender Foundation \ Blender \ 2.64 \ python \ lib \ thread ing.py「,第784行,在_bootstrap_inner中 with _active_limbo_lock: AttributeError:__exit__ –
Z4urce
2013-02-10 18:26:02
最好將它添加到問題中,以便將其格式化。 – phihag 2013-02-10 18:26:43