CUPS, GTK+, Python, and threading

Wednesday, December 17th, 2008

I’ve been trying to prevent a Python GTK+ application (the system-config-printer printing troubleshooter) from appearing to freeze when performing CUPS operations such as fetching a list of available devices.

Let me describe the problem.  In the libcups API the main worker function is cupsDoRequest() and this function blocks until the request is complete.  It may need to collect a password from the caller, in which case it will do this with a password callback function set using cupsSetPasswordCB().

The libcups API is used through a set of Python bindings called pycups, and GTK+ is used for the user interface.  The object of this game is to allow the GTK+ main loop to continue to run even while the CUPS operation is in progress.  I think I’ve got a workable system now.

(more…)