나는 프로세스에서 애니메이션 산포를 실행 중입니다. 모든 것을 끝내고 싶을 때 예외가 발생한다는 것을 제외하고는 모든 것이 잘 작동합니다. 예를 들어파이썬 (matplotlib)에서 애니메이션 플롯을 정상적으로 중지 (일시 중지하지 않음)
import multiprocessing as mp
import time
from collections import deque
def start_colored_scores(nb_channels):
q = mp.Queue()
process = mp.Process(target=colored_scores,args=(q,nb_channels,4000))
process.start()
return process,q
def colored_scores(q,nb_channels,size):
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, axes = plt.subplots(nrows=nb_channels,ncols=1,sharex=True,sharey=True)
plt.axis([-1.0,1.0,-1.0,1.0])
scats = [axe.scatter([0], [0], c="white", s=size) for axe in axes]
def animate(i):
scores = q.get()
if scores is None : # this is the external signal saying things should stop
plt.close()
return [axe.scatter([0], [0], c="white", s=size) for axe in axes]
scats = []
for score,axe in zip(scores,axes):
score = max(min(1,1-score),0)
scats.append(axe.scatter([0], [0], c=(1-score,0,score), s=size))
return scats
ani = animation.FuncAnimation(fig, animate, interval=1, blit=True)
plt.show()
, 이것이 잘 작동 :
_,q = start_colored_scores(2)
x = 0
right = 1
time_start = time.time()
while time.time()-time_start < 5:
if right==1 and x>1.0:
x = 1.0
right = -1
if right==-1 and x<0.0:
x = 0.0
right = 1
x+=right*0.02
q.put([x,1-x])
time.sleep(0.02)
q.put(None) # indicating I do not need plotting anymore
print "this is printed ... exception in the process ?"
행동은 내가 예상대로입니다 : 없앤다 표시하고 5 초 동안 애니메이션되어, 다음 프로그램이 계속됩니다.
AttributeError: 'NoneType' object has no attribute 'tk'
똑같은하지만 예외를 방지 할 수있는 방법이 있나요 : 유일한 문제가 발생되는 예외 (나는 과정에서 추측) 말하는 것입니다? 아니면이 예외를 어딘가에 잡으려고?
전체 스택 추적을 추가 할 수 있습니까? – Nathaniel