Issue with core.quit() when using PsychoPy through Spyder

Hi all,

I am using Spyder (5.2.2; Python 3.9.10) to run PsychoPy (in a dedicated Conda environment) on my M1 MacBook (Monterey, 12.0.1), but I cannot exit experiments using core.quit(). The experiment works fine using the PsychoPy coder. For reference, my Spyder preferences for Run > Console are set to “Execute in a dedicated console”.

This is the traceback I am seeing when I try to use a quit function which relies on core.quit() (this function is defined further down):

Exception ignored on calling ctypes callback function: <function ObjCSubclass.method.<locals>.decorator.<locals>.objc_method at 0x171862ee0>
Traceback (most recent call last):
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1141, in objc_method
    result = f(py_self, *args)
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/pyglet/window/cocoa/pyglet_view.py", line 199, in pygletKeyDown_
    self._window.dispatch_event('on_key_press', symbol, modifiers)
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/pyglet/window/__init__.py", line 1333, in dispatch_event
    if EventDispatcher.dispatch_event(self, *args) != False:
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/pyglet/event.py", line 415, in dispatch_event
    if getattr(self, event_type)(*args):
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/psychopy/visual/backends/pygletbackend.py", line 434, in onKey
    event._onPygletKey(evt, modifiers)
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/psychopy/event.py", line 233, in _onPygletKey
    _process_global_event_key(thisKey, modifiers)
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/psychopy/event.py", line 254, in _process_global_event_key
    r = event.func(*event.func_args, **event.func_kwargs)
  File "/Users/josh/Documents/Other Documents/Internship/AlexExp/First attempt (1).py", line 306, in quitfunction
    core.quit()
  File "/Users/josh/opt/anaconda3/envs/psychopyenv/lib/python3.9/site-packages/psychopy/core.py", line 88, in quit
    sys.exit(0)  # quits the python session entirely
SystemExit: 0

Quit function:

def quitfunction():
    print("---Global quit key pressed!---")
    core.quit()
event.globalKeys.add(key="p", func=quitfunction)

Thanks in advance!

I met the same problem, have you solved it now?