PsychoPy看起來正是我所需要的。但是我想使用自己的開發環境(與我選擇的編輯器結合的簡單IPython提示)而不是提供的IDE。pyglet在兩次運行PsychoPy演示時出現「無法共享上下文」異常
麻煩的是,你似乎必須退出Python並在每次PsychoPy運行後重新啓動。例如,如果我cd
到...../demos/coder/stimuli
目錄,鍵入run gabor.py
它運行良好,但如果我再次鍵入run gabor.py
我從pyglet得到此異常:
C:\snap\PsychoPy2\lib\site-packages\pyglet\window\win32\__init__.pyc in _create(self)
259 if not self._wgl_context:
260 self.canvas = Win32Canvas(self.display, self._view_hwnd, self._dc)
--> 261 self.context.attach(self.canvas)
262 self._wgl_context = self.context._context
263
C:\snap\PsychoPy2\lib\site-packages\pyglet\gl\win32.pyc in attach(self, canvas)
261 self._context = wglext_arb.wglCreateContextAttribsARB(canvas.hdc,
262 share, attribs)
--> 263 super(Win32ARBContext, self).attach(canvas)
C:\snap\PsychoPy2\lib\site-packages\pyglet\gl\win32.pyc in attach(self, canvas)
206 raise RuntimeError('Share context has no canvas.')
207 if not wgl.wglShareLists(share._context, self._context):
--> 208 raise gl.ContextException('Unable to share contexts')
209
210 def set_current(self):
ContextException: Unable to share contexts
是否有某種pyglet.cleanup()
我可以打電話(類似於pygame.quit()
)允許PsychoPy腳本在同一個會話中運行多次?或者以其他方式避免這個問題?
我正在使用Standalone PsychoPy發行版1.81.02,未觸及過。問題是不特定於IPython的---它也還可以從普通的Python提示如果禁用sys.exit
,並鍵入execfile('gabor.py')
兩次證明:
C:\snap\PsychoPy2\Lib\site-packages\PsychoPy-1.81.02-py2.7.egg\psychopy\demos\coder\stimuli>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import sys; sys.exit = lambda x:x
>>> execfile('gabor.py')
0.6560 WARNING Movie2 stim could not be imported and won't be available
1.6719 WARNING Monitor specification not found. Creating a temporary one...
>>>
>>> execfile('gabor.py')
Traceback (most recent call last):
[snip]
File "C:\snap\PsychoPy2\lib\site-packages\pyglet\gl\win32.py", line 208, in attach
raise gl.ContextException('Unable to share contexts')
pyglet.gl.ContextException: Unable to share contexts
有一個'pyglet.window.Window.close()'這將刪除當前窗口的所有方面,但是這必須是iniated窗口的對象本身上運行。所以你需要將你啓動的'Window()'放在一個變量中,並在其上調用'.close()'。但是,我認爲這沒什麼幫助,因爲你在某種包裝內運行它? – Torxed 2015-03-13 10:10:52