这是我的代码:
from psychopy import visual, event, gui, data, core
import random, os
from random import shuffle
from PIL import Image
import glob
a = glob.glob("DDtest/targetimagelist1/*")
b = glob.glob("DDtest/distractorimagelist1/*")
c = glob.glob("DDtest/targetimagelist2/*")
d = glob.glob("DDtest/distractorimagelist3/*")
e = glob.glob("DDtest/targetimagelist4/*")
shuffle(c)
shuffle(d)
ac = a + c
bd = b + d
indices = random.sample(range(len(ac)),len(ac))
ac = list(map(ac.__getitem__, indices))
bd = list(map(bd.__getitem__, indices))
ace = ac+e
shuffle(ace)
target = ac
distractor = bd
recognition = ace
def studyphase():
loc = [1, 2]
location = random.choice(loc)
if location == 1:
pos1 = [-.05,-.05]
pos2 = [.05, .05]
else:
pos1 = [.05, .05]
pos2 = [-.05, -.05]
win = visual.Window(size=(1920, 1080), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1])
distractorstim = visual.ImageStim(win=win, pos=pos1, size=[0.5,0.5])
distractorstim.autoDraw = True
targetstim = visual.ImageStim(win=win, pos=pos2, size=[0.5,0.5])
targetstim.autoDraw = True
targetstim.image = target[i]
distractorstim.image = distractor[i]
win.flip()
core.wait(.1)
def testphase():
win = visual.Window(size=(1920, 1080 ), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1])
recognitionstim = visual.ImageStim(win=win, pos=[0,0], size=[0.5,0.5])
recognitionstim.autoDraw = True
recognitionstim.image = recognition[k]
old = visual.TextStim(win,text='OLD',pos=[-0.5,-0.5],font='Lucida Console')
new = visual.TextStim(win,text='NEW', pos=[0.5,-0.5],font='Lucida Console')
old.draw()
new.draw()
win.flip()
core.wait(.1)
for i in range(len(ac)):
studyphase()
for k in range(len(ace)):
testphase()
这应该做的是拍摄一堆照片并在两个不同的阶段(学习和测试)显示它们,但是,当我运行此代码时,程序在第二个循环的一半左右崩溃,我收到以下错误消息:
python(55762,0xa0afe1a8) malloc: *** mach_vm_map(size=8388608) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Fatal Python error: (pygame parachute) Bus Error
但是,如果我独立运行研究循环或测试循环,它们运行良好。任何人都知道可能导致此错误的原因是什么?任何帮助将不胜感激。:)
编辑:很明显,如果我将 win 命令移到循环之外,它就可以工作。