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

HCtl event callback gives "Fatal Python error: drop_gil: drop_gil: GIL is not locked" #11

Open
HEnquist opened this issue May 14, 2024 · 4 comments

Comments

@HEnquist
Copy link

HEnquist commented May 14, 2024

I'm running the hctltest2.py test.

Then change one of the controls, I tried the "Z Test Volume" that gets numid 4:
amixer -D hw:0 cset numid=4 5

This generates and event, which runs the callback function. That results in the test script crashing, with:

Fatal Python error: drop_gil: drop_gil: GIL is not locked
Python runtime state: initialized

Thread 0x00007cae1adbc740 (most recent call first):
  File "/home/henrik/repos/camilladsp-controller/hctltest2.py", line 25 in event_callback

Current thread 0x00007cae1adbc740 (most recent call first):
  File "/home/henrik/repos/camilladsp-controller/hctltest2.py", line 63 in <module>

Extension modules: pyalsa.alsahcontrol (total: 1)
Aborted (core dumped)

Tested on manjaro with python 3.11, and latest alsa-python.

Also tested on Python 3.8.19, using the latest alsa-python code directly from this repo, with the same result.

@HEnquist
Copy link
Author

Update on this, maybe not a solution but perhaps a clue on what to do?
Commenting out the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS ain the handle_events() function at https://github.com/alsa-project/alsa-python/blob/master/pyalsa/alsahcontrol.c#L127
makes things work properly.

static PyObject *
pyalsahcontrol_handleevents(struct pyalsahcontrol *self, PyObject *args)
{
	int err;
	
	//Py_BEGIN_ALLOW_THREADS;
	err = snd_hctl_handle_events(self->handle);
	//Py_END_ALLOW_THREADS;
	if (err < 0)
		PyErr_Format(PyExc_IOError,
		     "HControl handle events error: %s", strerror(-err));
	Py_RETURN_NONE;
}

@perexg
Copy link
Member

perexg commented Jun 3, 2024

Unfortunately, I cannot reproduce this with latest master:

$ ./setup.py build
running build
running build_py
copying pyalsa/__init__.py -> build/lib.linux-x86_64-cpython-312/pyalsa
running build_ext
pyalsa/alsacard.so -> build/lib.linux-x86_64-cpython-312/pyalsa/alsacard.cpython-312-x86_64-linux-gnu.so
pyalsa/alsacontrol.so -> build/lib.linux-x86_64-cpython-312/pyalsa/alsacontrol.cpython-312-x86_64-linux-gnu.so
pyalsa/alsahcontrol.so -> build/lib.linux-x86_64-cpython-312/pyalsa/alsahcontrol.cpython-312-x86_64-linux-gnu.so
pyalsa/alsamixer.so -> build/lib.linux-x86_64-cpython-312/pyalsa/alsamixer.cpython-312-x86_64-linux-gnu.so
pyalsa/alsaseq.so -> build/lib.linux-x86_64-cpython-312/pyalsa/alsaseq.cpython-312-x86_64-linux-gnu.so
$ ./hctltest2.py
Watching (DEF): HDMI/DP,pcm=3 Jack,0
Watching (CLASS): HDMI/DP,pcm=4 Jack,0
Watching (DEF): Z Test Volume,1
Poll OK!
CALLBACK (DEF)! [VALUE] Z Test Volume:1
   (33, 33)

The command on the other console:

$ amixer -c 0 cset name="Z Test Volume",index=1 33
numid=51,iface=MIXER,name='Z Test Volume',index=1
  ; type=INTEGER,access=rw----W-,values=2,min=0,max=100,step=1
  : values=33,33

perexg added a commit to perexg/alsa-python that referenced this issue Jun 3, 2024
Link: alsa-project#11
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
@perexg
Copy link
Member

perexg commented Jun 3, 2024

Could you test code from PR #12 , if it solves something for you ?

@HEnquist
Copy link
Author

HEnquist commented Jun 3, 2024

It works great!
I tested both master and #12 a couple of times to make sure:

  • master -> fails as before
  • PR 12 -> works fine
  • master again -> still fails
  • PR 12 again -> works

Thanks for fixing!

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

No branches or pull requests

2 participants