summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2013-10-18 17:15:06 -0700
committerSimon Feltman <sfeltman@src.gnome.org>2013-10-18 17:42:27 -0700
commit0c308de528c402f67808b13760ca30d55d4c99d7 (patch)
tree1a097c97a24671543c786fda22a52b82abf9fe89
parenta2fa531b4dee73c193cac92fa3e870808688b5d7 (diff)
downloadpygobject-0c308de528c402f67808b13760ca30d55d4c99d7.tar.gz
Add threads_init back as a requirement for non-Python threaded repos
Re-add a "threads_init" function to gi for explicit intialization of Python threading support. This was marked as deprecated in the previous cycle because using Python threads already initializes everything. However, we still need an explicit initalization when using repositories with non-Python threads which may interact with Python callbacks (GStreamer). https://bugzilla.gnome.org/show_bug.cgi?id=710447
-rw-r--r--gi/__init__.py2
-rw-r--r--gi/gimodule.c10
-rw-r--r--gi/overrides/GLib.py11
3 files changed, 19 insertions, 4 deletions
diff --git a/gi/__init__.py b/gi/__init__.py
index 0645d448..1060005d 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -27,6 +27,7 @@ __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
@@ -35,6 +36,7 @@ gi # pyflakes
_API = _API # pyflakes
PyGIDeprecationWarning = PyGIDeprecationWarning
+threads_init
import os
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 9dfbd4ff..d84ecc02 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -600,6 +600,12 @@ 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 },
@@ -614,6 +620,10 @@ 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 }
};
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index ddd65bd1..8f18682f 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -23,6 +23,7 @@ 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)
@@ -48,10 +49,12 @@ spawn_async = _glib.spawn_async
def threads_init():
- warnings.warn('threads_init no longer needs to be called. '
- 'See: https://bugzilla.gnome.org/show_bug.cgi?id=686914',
- PyGIDeprecationWarning)
-
+ 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',
+ PyGIDeprecationWarning, stacklevel=2)
__all__ += ['GError', 'OptionContext', 'OptionGroup', 'Pid',
'spawn_async', 'threads_init']