psychopy/psychopy — Issue #99: fMRI launchScan Break and Fix
Author: kastman
Created: 2012-02-16 20:11:21+00:00
State: open

Hi all,

When running the experiment control -> fMRI_launchScan demo, v1.73.3 was not advancing - the experiment would initialize, but volumes weren't actually being sent (sync keys weren't being put into the event._keyBuffer, although manually pressing them would advance the scans). Instead, the instance of SyncGenerator running in a separate thread was crashing with an import error, but because it was not in the main thread the experiment was continuing:

```python
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.pyc", line 532, in __bootstrap_inner
File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.6/psychopy/hardware/emulator.py", line 111, in run
pyglet.media.dispatch_events() #events for sounds/video should run independently of wait()

110 if core.havePyglet:
111 pyglet.media.dispatch_events() #events for sounds/video should run independently of wait()
112 wins = pyglet.window.get_platform().get_default_display().get_windows()
113 for win in wins: win.dispatch_events() #pump events on pyglet windows
```

Even though pyglet has been imported into core, and the existence of pyglet has been checked (`if core.havePyglet:`), it's not available from emulator.py . From the little bits I've seen, this appears to be standard for Python namespacing, right? Checking sys.modules, pyglet had been imported, but wasn't available (`import sys; sys.modules.has_key('pyglet') >> True`).

Simply importing pyglet into emulator at the top of the file fixes the problem, but since this code has been changed to not require explicitly dispatching events from Pyglet anyway, its probably better to remove these lines wholesale (rescuing the NameError in a try block also works, but we can just get rid of them and the un-needed dependance). Finally, it seems like most of the other sound/multimedia aspects of the emulator have been commented out, so removing these lines seems overdue.

I've removed them in commit 6fc611bcb92ab95b3490709355e7d6ef27ef8b7d in my repo, and will try to attach a pull request. Hopefully that will make the emulator work for everyone again. Thanks!