| Reference | Downloads | Github

MemoryError or Too many open files with MovieStim3

Hi everyone,

OS: Win10
PsychoPy version: 1.90.3
Standard Standalone?: Yes. Using the coder.
What are you trying to achieve?: I have an experiment in which several short videos (~5 seconds each) with sound (required) are displayed. The experiment is divided into 5 blocks, with 8 trials each. One video is displayed on each trial.
What did you try to make it work? I play the videos with MovieStim3 and pygame as backend. I create just one video object per block, and then simply load a specific file on each trial.

What specifically went wrong when you tried that?
The experiment runs smoothly until it crashes, after ~32 videos. This is the error message I get:

  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\", line 163, in setMovie
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\visual\", line 180, in loadMovie
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\", line 111, in __init__
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\audio\io\", line 63, in __init__
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\audio\io\", line 50, in __init__
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\moviepy\video\io\", line 256, in ffmpeg_parse_infos
  File "C:\Program Files (x86)\PsychoPy2\lib\", line 745, in __init__
OSError: [Errno 24] Too many open files

What I have tried so far
Before this, I kept getting the MemoryError that other users have reported before. After trying different suggestions, reducing the size of the videos got rid of this error, but now I keep having the “too many open files” error. I’ve also tried to use MovieStim2, but didn’t manage to make it work, even though I have VLC installed (both PsychoPy and VLC are 32-bits versions).

I’ve seen this question has been asked before but was never answered, so I would very much appreciate some help!

One, I recommend Pyglet backend and upgrading to the latest version of PsychoPy3 if you can. I’ve found it to be a little more efficient with movie files.

Two, how much RAM does your computer have? If it’s less than 16GB I’m thinking you just need more RAM here.

Three, are these 32 different videos, or the same video files being loaded multiple times? There are ways to pause and loop videos instead of loading one for every trial and just refer back to different movie objects.

Overall I think you’re just hitting the RAM capacity of your system (Windows is especially bad about this), but it’s also possible there’s an issue with the raw number of things you’re loading, but I would be surprised. You could also try running this on a mac and see if it works better, if you have one on hand. For whatever reason I’ve found macs to be a little more efficient about loading video.

Hi @carlos,

I also encountered the “too many open files” bug with MovieStim3 lately.

After digging through the source, I used the following hack to ensure that my movie stimuli were deleted from memory after use.

After playing a movie, I call the following on my MovieStim3 object, called “encode” in my case:

del encode._mov.reader
del encode._mov

Maybe this also helps in your situation?

All the best,


This actually worked! Thanks a lot, Frank!