[pygobject] Add threads_init back as a requirement for non-Python threaded repos



commit 0c308de528c402f67808b13760ca30d55d4c99d7
Author: Simon Feltman <sfeltman src gnome org>
Date:   Fri Oct 18 17:15:06 2013 -0700

    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

 gi/__init__.py       |    2 ++
 gi/gimodule.c        |   10 ++++++++++
 gi/overrides/GLib.py |   11 +++++++----
 3 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/gi/__init__.py b/gi/__init__.py
index 0645d44..1060005 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 9dfbd4f..d84ecc0 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 ddd65bd..8f18682 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']


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]