[pygobject/pygobject-3-10] Fix toggleref safety problems by always enabling the GIL
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/pygobject-3-10] Fix toggleref safety problems by always enabling the GIL
- Date: Mon, 11 Nov 2013 13:47:55 +0000 (UTC)
commit 9c44080f95c4c73688a34cf8033605c049fed77d
Author: Simon Feltman <sfeltman src gnome org>
Date: Sun Oct 27 22:09:27 2013 -0700
Fix toggleref safety problems by always enabling the GIL
Call PyEval_InitThreads for the base gi module import. This forces the
Python internals create the GIL and always support threading with the
various thread state enter/exit funcs. This is needed since we cannot
predict which GI repositories might accept Python callbacks and run them in
non-Python threads or trigger toggle ref notifications in a thread other
than main.
https://bugzilla.gnome.org/show_bug.cgi?id=709223
gi/gimodule.c | 18 +++++++-----------
gi/overrides/GLib.py | 8 +++++++-
2 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 478a530..0d30b67 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -599,13 +599,6 @@ pyg_channel_read(PyObject* self, PyObject *args, PyObject *kwargs)
return NULL;
}
-static PyObject *
-_pygi_threads_init (PyObject *self, PyObject *dummy)
-{
- PyEval_InitThreads ();
- Py_RETURN_NONE;
-}
-
static PyMethodDef _gi_functions[] = {
{ "enum_add", (PyCFunction) _wrap_pyg_enum_add, METH_VARARGS | METH_KEYWORDS },
{ "enum_register_new_gtype_and_add", (PyCFunction) _wrap_pyg_enum_register_new_gtype_and_add,
METH_VARARGS | METH_KEYWORDS },
@@ -619,10 +612,6 @@ static PyMethodDef _gi_functions[] = {
{ "source_new", (PyCFunction) _wrap_pyg_source_new, METH_NOARGS },
{ "source_set_callback", (PyCFunction) pyg_source_set_callback, METH_VARARGS },
{ "io_channel_read", (PyCFunction) pyg_channel_read, METH_VARARGS },
- { "threads_init", (PyCFunction) _pygi_threads_init, METH_NOARGS,
- "Initialize Python threading support. This only needs to be called "
- "when using GI repositories with non-Python threads which may interact "
- "with Python callbacks (GStreamer)."},
{ NULL, NULL, 0 }
};
@@ -638,6 +627,13 @@ PYGLIB_MODULE_START(_gi, "_gi")
{
PyObject *api;
+ /* Always enable Python threads since we cannot predict which GI repositories
+ * might accept Python callbacks run within non-Python threads or might trigger
+ * toggle ref notifications.
+ * See: https://bugzilla.gnome.org/show_bug.cgi?id=709223
+ */
+ PyEval_InitThreads ();
+
if (pygobject_init (-1, -1, -1) == NULL) {
return PYGLIB_MODULE_ERROR_RETURN;
}
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 3eaba1f..c80a727 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -25,7 +25,7 @@ import sys
from ..module import get_introspection_module
from .._gi import (variant_new_tuple, variant_type_from_string, source_new,
- source_set_callback, io_channel_read, threads_init)
+ source_set_callback, io_channel_read)
from ..overrides import override, deprecated
from gi import PyGIDeprecationWarning, version_info
@@ -46,6 +46,12 @@ OptionGroup = _glib.OptionGroup
Pid = _glib.Pid
spawn_async = _glib.spawn_async
+
+def threads_init():
+ warnings.warn('Since version 3.10, calling threads_init is no longer needed. '
+ 'See: https://wiki.gnome.org/PyGObject/Threading',
+ PyGIDeprecationWarning, stacklevel=2)
+
__all__ += ['GError', 'OptionContext', 'OptionGroup', 'Pid',
'spawn_async', 'threads_init']
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]