Dear pygtk developers,

when gtk.set_interactive() is used, the PyOS_InputHook that pygtk 
installs holds the global Python lock indefinitely, until the user 
presses enter on the console (until newline is read on stdin).

This is a major change from Python's default interactive behaviour, 
which regularly releases the lock.

The changed behaviour causes multithreaded code that relies on 
background access to the Python interpreter to stall, also 
indefinitely.

To fix, I propose that the glib poll function is customized using 
g_main_context_set_poll_func().  On UNIX systems a suitable custom 
function could look like this (slightly modified code taken from a 
different application with similar requirements):

#include <poll.h>

static gint
_g_pollfunc (GPollFD * fds, guint n, gint timeout)
{
  PyThreadState * tstate;
  int r;

  /* replace indefinite timeout with 100 ms */
  if (timeout < 0) timeout = 100;

  /* release the Python lock while in poll() */
  tstate = PyEval_SaveThread();
  r = poll ((pollfd *) fds, n, timeout);
  PyEval_RestoreThread (tstate);

  return r;
}

I should add that I'm currently not subscribed to this list.

Cheers, Tim
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to