PsychoPy keyboard.Keyboard() - PsychHID KbQueueStart - Memory fault

I’m getting a reliable “Memory fault” error trying to set up the keyboard input for PsychoPy. I’ve narrowed the issue down to the PsychHID KbQueueStart call.

Question: Is there a way to turn up the verbosity of psychtoolbox via Python to maybe get more debug info?

Additional Details:

Using the following script:

#!/usr/bin/env python

import time
from psychtoolbox import PsychHID
print("DEBUG: KbQueueCreate")
PsychHID('KbQueueCreate', 4)
print("DEBUG: wait #1")
time.sleep(5)
print("DEBUG: KbQueueStart")
PsychHID('KbQueueStart', 4)
print("DEBUG: wait #2")
time.sleep(5)
print("DEBUG: done")

I get:

>python test.py
DEBUG: KbQueueCreate
PsychHID-INFO: libX11 library not yet set up for thread-safe operation by host application, as required.
PsychHID-INFO: Now calling XInitThreads() myself, to fix this problem in a likely safe way.
DEBUG: wait #1
DEBUG: KbQueueStart
DEBUG: wait #2
Memory fault

I suspect that this issue is specific to my system (though I haven’t tried it on any other) - some details:

>cat /etc/centos-release 
CentOS Linux release 7.7.1908 (Core)
>python -V             
Python 3.6.8
>psychopy -v    
PsychoPy3, version 2020.1.2 (c)Jonathan Peirce 2018, GNU GPL license
>pip list | egrep psych
psychtoolbox    3.0.16

Additional notes:

  • I added time.sleep() calls to the test script because … threads. This confirms that the Memory fault is caused by PsychHID KbQueueStart, and not something earlier.
  • The note about XInitThreads() is puzzling, not sure if it’s related to this issue.
  • The device number used in the test script (4) is not relevant, all valid device numbers return the same results.

Just noting that this may be more of a question of how to install psychtoolbox (PTB) on this particular Linux distro (CentOS 7). I did replicate this issue on another machine, so I can confirm that it is not hardware-specific.

Based on the install instructions I added the following packages before installing PTB:
>sudo yum install -y alsa-lib-devel portaudio-devel libusb-devel
The installation was successful, but as per the error above, PTB does not work. The issue may well be one of the problems listed here, but I have not gone further with this.

Luckily, PTB is optional for PsychoPy, so I just installed PsychoPy without PTB for now.

A few notes, unfortunately none that directly address your issue:

  • As far as I can tell, there are no flags/settings to increase the verbosity of PsychHID, even in the source for Psychtoolbox. Debugging might involve tools like gdb.
  • The XInitThreads() bit should be harmless-- it’s just part of making sure the host application is set up to do proper multithreading.
  • I think the install instructions are a little out of date. Psychtoolbox manylinux2010 wheels have been on PyPI since Feb 2020 (https://pypi.org/project/psychtoolbox/#files), and extra dependencies are bundled with the wheel (i.e. pip install psychtoolbox should be sufficient?). It would be good to know if that isn’t the case, though.
  • Unfortunately, I can’t reproduce this issue on my Ubuntu 18.04 laptop with the PyPI wheel + Python 3.7/3.8. I may have the Octave flavor of Psychtoolbox installed though, so not the cleanest testing environment…
  • Do other parts of psychtoolbox work, e.g. PsychPortAudio & GetSecs()/WaitSecs()? There are some small demos here: https://github.com/Psychtoolbox-3/Psychtoolbox-3/tree/master/PsychPython/demos

Thanks for looking at this @aforren1.

The ppatest runs fine.
The hidtest dies with Memory fault, and last message is:

PTB-CRITICAL: In call to PsychSetThreadPriority(): Failed to set new basePriority 2, tweakPriority 1, effective 1 [REALTIME] for thread (nil) provided!
Memory fault

which looks the same as the permission issue mentioned here.

Have you tried modifying cap_sys_nice for the python executable as described here: Psychtoolbox manylinux2010 wheels? I don’t think the full PTB install is strictly necessary…

1 Like

That was the first time I have seen the PTB-CRITICAL error, so I did not make the connection. Your suggestion worked great, and no more Memory fault:

>sudo setcap cap_sys_nice=eip `readlink -f \`which python\``

Thank you!