OS (e.g. Win10): Win11
PsychoPy version:2025.1.1 Py 3.10
Standard Standalone Installation? (y/n) yes
In my experiment, I will need to provide immediate feedback based on participants’ responses. Basically, in each trial, the screen shows a reward whenever participants click one of the targets on the display. There are multiple targets on one display. The amount of reward start from 0 in each trial. The simplified code is the following:
------------before experiment--------
def makeApples(appleCounts,applesList,appleSizes,applePosX):
apples=[]
for i in range(appleCounts):
apple = visual.ImageStim(
win=win, texRes=128.0,interpolate = True
)
apples.append(apple)
return apples
def drawApples(apples):
for each in apples:
each.draw()
def makeBoxes(boxCounts,boxPosX):
boxes=[]
for i in range(boxCounts):
box = visual.ImageStim(
win=win, image="image/box.png",interpolate = True
)
boxes.append(box)
return boxes
def drawBoxes(boxes):
for each in boxes:
each.draw()
--------------each Frame-------------
for clickable in treeImages:
if imageMouse2.isPressedIn(clickable):
if clickedImage == None:
clickedImage = clickable
tempString = clickedImage.name
treeNum = int(tempString.replace("tree", ""))
applesList.append(appleImages[treeNum].image)
appleSizes.append(appleSize[treeNum][1][applesCount])
appleSizesLists.append(appleSize[treeNum][0])
applesCount +=1
break
else:
break
boxes=makeBoxes(horizon,rewardPosX)
drawBoxes(boxes)
apples=makeApples(applesCount,applesList,appleSizes,rewardPosX)
drawApples(apples)
Then I went into the following problem after around 20 trials:
######## Experiment ended with exit code 1 [pid:30984] #########
Generating PsychoPy script…2668.4706 INFO Loaded monitor calibration from [‘2024_10_22 15:53’]
2668.5433 INFO Loaded monitor calibration from [‘2024_10_22 15:53’]
Traceback (most recent call last):
File “D:\documents\research_projects\Leechi\a2_material_and_methods\test\horizonsTask_trees\horizonTreeTask_lastrun.py”, line 1776, in
run(
File “D:\documents\research_projects\Leechi\a2_material_and_methods\test\horizonsTask_trees\horizonTreeTask_lastrun.py”, line 1183, in run
boxes=makeBoxes(horizon,rewardPosX)
File “D:\documents\research_projects\Leechi\a2_material_and_methods\test\horizonsTask_trees\horizonTreeTask_lastrun.py”, line 403, in makeBoxes
box = visual.ImageStim(
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py”, line 111, in init
self.setImage(image, log=False)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py”, line 452, in setImage
setAttribute(self, ‘image’, value, log)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py”, line 191, in setAttribute
setattr(self, attrib, value)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\tools\attributetools.py”, line 69, in set
newValue = self.func(obj, value)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\image.py”, line 427, in image
self.isLumImage = self._createTexture(
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1149, in _createTexture
intensity = numpy.array(im)
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 3.44 MiB for an array with shape (950, 950, 4) and data type uint8
215.8139 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
215.8564 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
215.8565 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
215.8565 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
######### Experiment ended with exit code 1 [pid:7412] #########
Here, the message shows the error is from the boxes, but sometimes it can also come from the apples.
I tried the following code as suggested by AI to free up the memory, but it doesn’t work:
treeImages.clear()
apples.clear()
boxes.clear()
del treeImages
del apples
del boxes
gc.collect()
Then I try to reduce the pixel of all the pictures and put the texRes=64.0. It can go on for almost 100 trials. But it either went into the same numpy Memory Error or another memory problem, which comes with the whole screen going dark and coming back on again:
Generating PsychoPy script...
## Running:
75.0612 INFO Loaded monitor calibration from ['2024_10_22 15:53']
75.1332 INFO Loaded monitor calibration from ['2024_10_22 15:53']
50.7363 WARNING Keypress was given unknown key code (176)
Traceback (most recent call last):
50.9105 WARNING Keypress was given unknown key code (176)
51.9067 WARNING Keypress was given unknown key code (176)
52.0430 WARNING Keypress was given unknown key code (176)
52.1744 WARNING Keypress was given unknown key code (176)
52.3450 WARNING Keypress was given unknown key code (176)
52.5084 WARNING Keypress was given unknown key code (176)
52.6742 WARNING Keypress was given unknown key code (176)
52.8415 WARNING Keypress was given unknown key code (176)
53.0088 WARNING Keypress was given unknown key code (176)
53.1391 WARNING Keypress was given unknown key code (176)
File "...", line 1773, in <module>
run(
File "...", line 1297, in run
win.flip()
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\window.py", line 1419, in flip
GL.glFinish()
File "C:\Program Files\PsychoPy\lib\site-packages\pyglet\gl\lib.py", line 106, in errcheck
raise GLException(msg)
pyglet.gl.lib.GLException: b'out of memory'
50.7363 WARNING Keypress was given unknown key code (176)
50.9105 WARNING Keypress was given unknown key code (176)
51.9067 WARNING Keypress was given unknown key code (176)
52.0430 WARNING Keypress was given unknown key code (176)
52.1744 WARNING Keypress was given unknown key code (176)
52.3450 WARNING Keypress was given unknown key code (176)
52.5084 WARNING Keypress was given unknown key code (176)
52.6742 WARNING Keypress was given unknown key code (176)
52.8415 WARNING Keypress was given unknown key code (176)
53.0088 WARNING Keypress was given unknown key code (176)
53.1391 WARNING Keypress was given unknown key code (176)
1273.9413 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0330 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0331 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0331 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
Exception ignored in atexit callback: <function flush at 0x0000022726AC08B0>
Traceback (most recent call last):
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\logging.py", line 323, in flush
logger.flush()
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\logging.py", line 308, in flush
formatted[thisEntry] = self.format.format(**thisEntry.__dict__)
MemoryError:
50.7363 WARNING Keypress was given unknown key code (176)
50.9105 WARNING Keypress was given unknown key code (176)
51.9067 WARNING Keypress was given unknown key code (176)
52.0430 WARNING Keypress was given unknown key code (176)
52.1744 WARNING Keypress was given unknown key code (176)
52.3450 WARNING Keypress was given unknown key code (176)
52.5084 WARNING Keypress was given unknown key code (176)
52.6742 WARNING Keypress was given unknown key code (176)
52.8415 WARNING Keypress was given unknown key code (176)
53.0088 WARNING Keypress was given unknown key code (176)
53.1391 WARNING Keypress was given unknown key code (176)
1273.9413 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0330 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0331 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
1274.0331 WARNING Stopping key buffers but this could be dangerous ifother keyboards rely on the same.
Exception ignored in: <function _Logger.__del__ at 0x0000022726AC0C10>
Traceback (most recent call last):
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\logging.py", line 256, in __del__
File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\logging.py", line 308, in flush
MemoryError:
######## Experiment ended with exit code 1 [pid:22432] #########
I need to do at least 200 trials for the experiment, and I wonder if anyone has any idea how to solve it. Thank you so much in advance.