| Reference | Downloads | Github

Crashes after 30 mins/ wavs have clicks/ can't use MIDI files

I’m using psychopy for a pitch to melody association training task, which collects data as it goes.

My coding ability is much better than it used to be, but still pretty terrible really. It’s got to the point where I can usually get python (and matlab) to do what I want it to do, but in an incredibly inelegant and verbose kind of way, with lots of room for stupid mistakes along the way… As such if you could pitch any responses at the level of dribbling idiot then that would be greatly appreciated… thanks!


I have a huge while loop that I intend people to use for long periods of time (e.g. an hour). It works basically fine until about 30 mins in when it crashes my computer… I’m thinking this might be because the experiment is saving so much data by this point that it can’t handle it anymore… is there any way in which I can save the data to the logfile/excel file etc as I go, and routinely flush out the saved data from psychopy as I do so?


The .wav files play with weird clicks in them - has anyone else had this issue? I’ve checked the files themselves and they seem to be fine.


I’m using 4350 .wav files, from which a function I’ve created picks a few semi-random ones (between 12 and 24, depending on the progression through the training) on each time through the loop. These files unsurprisingly take up a pretty ridiculous amount of space… (I intuitively wonder if the sheer quantity of files is responsible for some of the performance issues previously mentioned, although I’d have thought it isn’t as conditions are replaced on each iteration of the loop - so it should only be having to handle between 12 and 24 files at any given time). This would be a lot more space efficient if I used MIDI files instead, but I couldn’t get PsychoPy to run when I tried using MIDI files - is there a trick to this?

Thanks for the help!

Any thoughts on this? Really struggling… Best wishes all!

Regarding Issue 2: What version of PsychoPy are you using? Recently there was a hanning bug fix to remove the clicks - see Github #1718.

Thanks for that - I’ve been using version 1.85.4 - is that one ancient now then? Thanks for the tip off

so looks like 1.90.1 is the current? I’ll download and see if it fixes it - thanks :slight_smile:

Ok so now I’ve updated PsychoPy my code doesn’t work anymore. Getting this:

Traceback (most recent call last):
File “/Users/sam/Downloads/AP_experiment_1/”, line 872, in
exec(paramName + ‘= thisTrial.’ + paramName)
File “”, line 1, in
AttributeError: ‘OrderedDict’ object has no attribute ‘audioStim’


I’ll give this some thought tomorrow… thanks for your help :slight_smile:

Looks like you aren’t alone in encountering this bug:

@dvbridges this seems like a general issue we should get to the bottom of. I seem to recall some recent change where there was a shift to ordered dicts, perhaps by @richard , to yield more predictable behaviour, although that change may not itself be the source of this error.

Thanks @Michael, I will try to recreate the error and see what is happening. Hey @richard, if you have any insights it would be good to hear from you.

Not wanting to drop this in your lap, David, was more musing to myself but thought I should get it noted down.

@Sam_Leak: any chance you could help out by producing a minimal reproducible example of this latest bug (i.e. one that doesn’t need access to your 4350 sound files…)? It would help a lot in figuring out what is causing this.

1 Like

Hi Michael

I can try to do that on Friday! A bit hectic until then…

In other news I had to go back to an older version today in order to check a student’s work. I had been on 1.85.4 (prior to yesterday’s change up to 1.90.1), but I decided to try going back to 1.85.6. Everything worked fine again. The clicking on the audio was still there (felt like there was a lot less of it than I was having on 1.85.4 - should that be the case, or is that just a random occurrence?)

The other weird quirk is that it’s started saving two copies of the data file for every run of the experiment…?

Anyway I’ll get on with trying to make a a minimal reproducible example for you on Friday. If you’ve already found the issue by then then lemme know!

Any thoughts on Issue 1 from above?

Thanks :slight_smile:

W/r/t issue 1 you should be able to set it up so you have a single data structure for a line of data that writes immediately and gets reset in the next loop. It might still run into issues but that’s the best I can think of.

The basic structure would be something like:

with open('fileName.csv', 'ab') as fp: #ab because windows. 
    a = csv.writer(fp, delimiter=',',lineterminator='\r\n')
    data = yourData

Then you can just rewrite the “yourData” structure on every loop.

1 Like

Thanks Jonathan! Michael - I’m just looking into this now (unless it’s already been dealt with elsewhere?) - sorry it’s been a hectic couple of weeks

Here you go everyone:

I’ve isolated the (large) bit of code that’s causing me all of the problems, and I’ve reduced the number of .wav files (significantly) to the smallest number at which the experiment structure makes sense. The error message, possibly due to ordered dicts, is still appearing if I open it in PsychoPy v1.90.1, and it does not appear if I open it in v1.85.6 - so hopefully you’ll find that useful @Michael and @dvbridges ?

Jonathan - the variable that keeps growing excessively large is ‘thisExp’, isn’t it? I’m presuming what I’d need to do is regularly reset thisExp within the code then, and save the data on each attempt? Or would you try to run everything without an experiment handler? In your suggestion above, would ‘yourData’ equate to ‘thisExp’?

Thanks all!

I’m starting to feel like I’ve bitten off more than I can chew with all of this. As you will see if you open the file, my coding isn’t particularly elegant and is probably full of errors (even though it appears to work other than the issues listed in my original post). Do any of you live in London (where I teach) or Cambridge (where I study)? Would anyone PsychoPy savvy in either of those places be up for me paying them for an hour or two of their time to go through my code with me… What with the clicks and the crashing, I’ve hit a bit of a brick wall with all of this…

Did that help at all? No worries if not! If it’s been figured out elsewhere on here during my week and a half away then could you point me in the direction of the answer?

Sorry, haven’t had a chance to look at this in a week. Basically to use my suggestion for the data issue you would need to change how data is being recorded. Right now, because you are using trialHandler and experimentHandler, data for every trial is written with addData to a big honking object in memory. If that’s what’s getting overloaded, you’ll need to record your data without using addData. That means pulling all the information you would get from trialHandler (all the columns) without using trialHandler, build your own list, and then use the code I provided above. Basically you would just be using experimentHandler and trialHandler to set up your order of trials, but not record data with them. Not sure if that would help or not, though, because it may save some of that data regardless. I don’t use trialHandler or experimentHandler much, so I’m not totally sure how they’re put together.

1 Like