这是我的代码:
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命令,它就可以了。
答案 0 :(得分:2)
几年前这个问题是raised on the psychopy-users list。很可能是由于图像太大(以像素为单位,而不是兆字节)。因此,如果可能的话,解决方案是将它们缩减到大约您要显示它们的分辨率。我通过谷歌搜索错误信息找到了这个。
在每个试验/演示中生成一个新窗口和几个新的刺激,因为它们是在函数内启动的,并且在循环的每次迭代中都会调用函数。请see my answer to your earlier question获取先创建窗口/刺激的策略,然后更新需要更改的属性。这甚至可以解决这个问题,因为创造新的刺激可能会填满记忆。