0

While running some older Python+GTK3 code under Ubuntu 14.04, the following deprecation warnings appeared:

PyGIDeprecationWarning: io_add_watch is deprecated; use GLib.io_add_watch instead
/usr/lib/python3/dist-packages/gi/overrides/GLib.py:655: PyGIDeprecationWarning: Calling io_add_watch without priority as second argument is deprecated
/usr/lib/python3/dist-packages/gi/overrides/GLib.py:666: PyGIDeprecationWarning: Calling io_add_watch with priority keyword argument is deprecated, put it as second positional argument

This comes from a line where GObject.io_add_watch() is called.

From http://www.piware.de/2012/11/pygobject-3-7-2-released/ and http://lazka.github.io/pgi-docs/api/GLib_2.0/functions.html?highlight=add_watch#GLib.io_add_watch it looks like the parameter profile for GLib.io_add_watch() is different from GObject.io_add_watch(). So now I'm wondering:

  1. what is the correct way to set an I/O watch on an fd in Python+GTK3? Which function to use, what parameter profile to use?
  2. how can I write the code in a way that it is compatible with older systems, eg. Ubuntu 12.04?

Can anyone with experience with this API in old and new systems give some hints?

oliver
  • 6,204
  • 9
  • 46
  • 50

2 Answers2

0

GLib.io_add_watch() has existed for a long time: It was already there much before Ubuntu 12.04 was released. So the correct thing is to use that.

I think the function signature is pretty similar, apart from the priority: you should probably use GLib.PRIORITY_DEFAULT.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
  • No luck yet... on 14.04 I need to call it like this: GLib.io_add_watch(theFd, prio, GLib.IO_IN, onReadable); but on 12.04 it must be called like this: GLib.io_add_watch(theFd, GLib.IO_IN, onReadable, priority=prio). Using the wrong parameter profile on either system results in exceptions or warnings. Should I seriously add some run-time version check here to find the correct invocation? – oliver Feb 27 '14 at 23:07
  • I don't think a run-time version check is so unreasonable given that you're dealing with (unfortunately) changing API. – ptomato Feb 28 '14 at 04:57
  • 1
    @oliver oh, sorry for misleading: I hand't noticed the python wrapper had changed along the way. There's an alternative solution to runtime version checking: name all of the arguments you give. Then the order does not matter. – Jussi Kukkonen Feb 28 '14 at 08:28
  • 1
    jku, thanks for the hint! Looks like the 12.04 bindings don't like named arguments, though ("TypeError: io_add_watch requires at least 3 args") - maybe a simple bug in that version. I've switched to a version check now ("if GObject.pygobject_version < (3, 7, 2)"), which is ugly but should work otherwise. – oliver Feb 28 '14 at 20:31
0

A deprecation warning means the functionality in use will be removed in the next major version of PyGObject (which there are currently no plans for). Deprecation warnings only show up in development versions of PyGObject (odd minor version numbers) or when using the -Wd Python command line option to enable deprecation warnings.

If you need to keep compatibility with PyGObject versions prior to 3.7.2, your best bet is to continue using the deprecated version which should work across the entire 3.x series:

GObject.io_add_watch(theFd, GLib.IO_IN, onReadable, priority=prio)

If this does not work in some version of PyGObject, it is an API break and therefor a bug, please log it here:

https://bugzilla.gnome.org/enter_bug.cgi?product=pygobject

Simon Feltman
  • 1,120
  • 7
  • 8