Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

trouble using the inline script logger

edited October 2017 in OpenSesame

Hi all,

I tried using the logger in an inline script as I need to log variables in an inline loop.

I wrote: " log.write_vars()"

And I get the error message:

Error while executing inline script

item-stack: experiment[run].Ego_depletion_task[run].new_inline_script[run]
exception type: ValueError
exception message: I/O operation on closed file.
item: new_inline_script
time: Sun Oct 15 18:13:21 2017
phase: run

What am I missing here?

Thanks!

Comments

  • Hi Amir,

    I suspect that you've inadvertently closed the logfile, and then try to write to it. For example, the following script will result in the error that you're seeing, and something similar is probably going on in your experiment.

    log.close()
    log.write_vars()
    

    Could that be it?

    Cheers,
    Sebastiaan

  • Hi Sebastiaan,

    Yes, now that you bring it up, there is something in the setup of the experiment, that I put in to create unique logfiles. I looks like the log file is reopened though, but I gues it was only initialised.

        import os
        # Close the current logfile
        exp._log.close()
        # Check for each session number whether a file called
        # `[subject nr]-[session nr].csv` already exists, and pick the first session
        # number which does *not* exist.
        for session_nr in range(0, 1000):
            path = 'ego_s%d-%d.csv' % (self.get('subject_nr'), session_nr)
            if not os.path.exists(path):
                break
        print 'Using %s' % path
        exp.logfile = path
        # Reopen the logfile
        exp._log = None
        exp.init_log()
    
        exp.set("session_nr", session_nr)
    

    I added this line and now it works, thanks!

        log.open(path)
    
Sign In or Register to comment.