Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local experiment will crash #7

Open
fnielsen opened this issue Apr 9, 2014 · 1 comment
Open

local experiment will crash #7

fnielsen opened this issue Apr 9, 2014 · 1 comment
Assignees
Labels

Comments

@fnielsen
Copy link

fnielsen commented Apr 9, 2014

Having the experiment in a local namespace will crash the expyriment process with no meaningful error message

def main():
    exp = design.Experiment("Left right")
    ...

if __name__ == "__main__":
    main()
@fladd
Copy link
Member

fladd commented Apr 14, 2014

Yes, that is correct. The problem relates to the fact that we internatlly just do an execfile() on the Expyriment script and we explicitly set the global dict to the global dict of the file which calls the script (the main.py of the Android Runtime Environment).
We are aware that this is a hack (and a pretty bad one actually, see also: https://lucumr.pocoo.org/2011/2/1/exec-in-python/).
One option to solve this properly would be to always insist on having the Expyriment script wrapped into a main function (as in your example). Doing this we could just import the file as a module and call the main function. The only reason we initially did not do this is because we wanted every Expyriment script to run without modification. Your example shows that this approach failed and I think wrapping everything in a main function is good Python practice anyway.
So, yes, we certainly have to reconsider our current implementation.

Thanks for spotting this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants