[pygobject] Fix toggleref safety problems by always enabling the GIL
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix toggleref safety problems by always enabling the GIL
- Date: Mon, 28 Oct 2013 05:33:49 +0000 (UTC)
commit 65b8f7bd77474e361c80905ec23de6dbde27970c
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/__init__.py | 2 --
gi/gimodule.c | 18 +++++++-----------
gi/overrides/GLib.py | 8 ++------
3 files changed, 9 insertions(+), 19 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index 1060005..0645d44 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -27,7 +27,6 @@ __path__ = extend_path(__path__, __name__)
from ._gi import _API
from ._gi import Repository
from ._gi import PyGIDeprecationWarning
-from ._gi import threads_init
# Force loading the GObject typelib so we have available the wrappers for
# base classes such as GInitiallyUnowned
@@ -36,7 +35,6 @@ gi # pyflakes
_API = _API # pyflakes
PyGIDeprecationWarning = PyGIDeprecationWarning
-threads_init
import os
diff --git a/gi/gimodule.c b/gi/gimodule.c
index d84ecc0..12addbc 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -600,13 +600,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 },
@@ -620,10 +613,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 }
};
@@ -639,6 +628,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 fc25882..fc38f69 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -23,7 +23,6 @@ import signal
import warnings
import sys
-import gi
from ..module import get_introspection_module
from .._gi import (variant_new_tuple, variant_type_from_string, source_new,
source_set_callback, io_channel_read)
@@ -49,11 +48,8 @@ spawn_async = _glib.spawn_async
def threads_init():
- gi.threads_init()
- warnings.warn('Since version 3.10, threads_init is no longer needed when mixing Python '
- 'threads with GI. If you are using GI repositories with non-Python threads '
- 'which may interact with Python callbacks (GStreamer), use: gi.threads_init() '
- 'to get rid of this message. See: https://wiki.gnome.org/PyGObject/Threading',
+ warnings.warn('Since version 3.11, calling threads_init is no longer needed. '
+ 'See: https://wiki.gnome.org/PyGObject/Threading',
PyGIDeprecationWarning, stacklevel=2)
__all__ += ['GError', 'OptionContext', 'OptionGroup', 'Pid',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]