After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 731091 - Add option to skip gdk_init and gtk_init calls when importing Gdk and Gtk
Add option to skip gdk_init and gtk_init calls when importing Gdk and Gtk
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 723736
Blocks:
 
 
Reported: 2014-06-01 22:35 UTC by Simon Feltman
Modified: 2018-01-10 20:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add option to disable automatic init_check calls upon import of Gtk and Gdk (2.58 KB, patch)
2014-06-02 00:16 UTC, Simon Feltman
none Details | Review

Description Simon Feltman 2014-06-01 22:35:31 UTC
Auto initialization gives rise to some technical problems and confusion with the rest of the GNOME stack (bug 729643).

We really should not implicitly use or modify sys.argv as a side effect of an import statement anyhow. The reason this is bad is because it removes control of command line parsing from application developers. For example, if an app wanted to use the "--name" option, this conflicts with Gdk which parses "--name" in its init. So you'd have to hack around that with:

  old_args = sys.argv
  sys.argv = ['']
  from gi.repository import Gdk
  sys.argv = old_args

The proposal is a add a switch to gi that the Gdk and Gtk overrides can look at when they are imported:

  import gi
  gi.options['no_repo_auto_init'] = True
  from gi.repository import Gtk
  ...
  Gtk.init()

Eventually, the auto initialization should be removed if possible.
Comment 1 Simon Feltman 2014-06-02 00:16:26 UTC
Created attachment 277704 [details] [review]
Add option to disable automatic init_check calls upon import of Gtk and Gdk

Add gi.options['gtk_gdk_init_on_import'] which is True by default.
Setting to False prior to importing Gtk or Gdk allows better control
over sys.argv and init ordering after import statements (bug 729643).

Notes:
There is currently not a lot we can do to test this because we first need
more robust testing features to support tests run in a new process
(a generic approach to how pygtkcompat is tested).
Comment 2 Emmanuele Bassi (:ebassi) 2015-04-30 12:29:27 UTC
Another couple of reasons why it's bad:

 * modules may end up importing Gdk/Gtk implicitly and end up initializing things out of order
 * we have a bunch of API that ought to be called before initialization, which is impossible to do with init-on-import
Comment 3 GNOME Infrastructure Team 2018-01-10 20:43:07 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/72.