Howdy, Stranger!

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

Supported by

[solved] Prepare Phase

edited July 2015 in OpenSesame

Could someone please confirm (or otherwise) that the prepare phase of all Python inline scripts, in ones experiment, are run at the initial start up? (As opposed to being run sequentially, as you progress to the relevant item.)

I noticed that my SQLite connection was getting closed, even though I hadn't issued any close command until the final item's prepare phase. If I move the close into the run phase, then it works... I've been going mad trying to understand why it kept closing itself and the above would be a justifiable explanation :)

Thanks;
C

Comments

  • edited July 2015

    ...although, if that were the case, what is happening with variable assignment? If I declare a variable in the prepare phase, I can still use it in the run phase contextually; that is, it respects any dependencies said variable might have (e.g., a loop index), rather than overwriting the value.

    I would be interested in knowing how this works at a technical level. I'm a developer by profession and I'm finding a lot of "gotchas" are to do with my mental model vs. the compromises you've put in place to allow non-developers to use OpenSesame more intuitively. (Not that that's a complaint! I think it's a good design decision, in general, and am impressed that you went to the trouble of implementing it :) )

  • edited 10:03AM

    Could someone please confirm (or otherwise) that the prepare phase of all Python inline scripts, in ones experiment, are run at the initial start up? (As opposed to being run sequentially, as you progress to the relevant item.)

    Not exactly. The prepare phase of every item in a sequence, is executed at the start of that sequence. So say that you have a sequence s, with items i1 and i2, then it would go like this:

    • run s
      • prepare i1
      • prepare i2
      • run i1
      • run i2

    But this happens only at the sequence level; or, put differently, sequences don't have a prepare phase themselves, and everything that you see above would happen as part of a sequence run phase.

    Does that clear things up? You could visualize the flow of the experiment by having inline_script items print to the debug window in both the prepare and run phase.

    See also:

    ...although, if that were the case, what is happening with variable assignment? If I declare a variable in the prepare phase, I can still use it in the run phase contextually; that is, it respects any dependencies said variable might have (e.g., a loop index), rather than overwriting the value.

    I'm not sure what you mean here. Can you give an example?

    I'm a developer by profession and I'm finding a lot of "gotchas" are to do with my mental model vs. the compromises you've put in place to allow non-developers to use OpenSesame more intuitively.

    That's true, and one of the main challenges when designing OpenSesame.

    Cheers!
    Sebastiaan

  • edited 10:03AM

    Thanks, Sebastiaan

    That clears everything up and resolves my issue/misunderstanding with variable assignment persistence. I was thinking you must use a closure, or something like that, but Python doesn't really have proper closures. Scoping by sequence is a nice solution :)

Sign In or Register to comment.