pygtk r3038 - in trunk: . docs/reference gtk



Author: paulp
Date: Mon Sep  8 21:05:26 2008
New Revision: 3038
URL: http://svn.gnome.org/viewvc/pygtk?rev=3038&view=rev

Log:
2008-09-09  Paul Pogonyshev  <pogonyshev gmx net>

	Bug 539475 â gtk.gdk.threads_(enter|leave) promote dead-lock-prone
	synchronization

	* gtk/__init__.py (gdk.lock): New context manager.

2008-09-09  Paul Pogonyshev  <pogonyshev gmx net>

	* pygtk-gdk-functions.xml: Document new `gtk.gdk.lock'.


Modified:
   trunk/ChangeLog
   trunk/docs/reference/ChangeLog
   trunk/docs/reference/pygtk-gdk-functions.xml
   trunk/gtk/__init__.py

Modified: trunk/docs/reference/pygtk-gdk-functions.xml
==============================================================================
--- trunk/docs/reference/pygtk-gdk-functions.xml	(original)
+++ trunk/docs/reference/pygtk-gdk-functions.xml	Mon Sep  8 21:05:26 2008
@@ -511,7 +511,10 @@
 	<methodname><link
 linkend="function-gdk--threads-leave">gtk.gdk.threads_leave</link></methodname>
 	<methodparam></methodparam>
-  </methodsynopsis><methodsynopsis language="python">
+  </methodsynopsis><synopsis language="python">
+	  <varname><link
+linkend="function-gdk--lock">gtk.gdk.lock</link></varname>
+  </synopsis><methodsynopsis language="python">
 	<methodname><link
 linkend="function-gdk--threads-init">gtk.gdk.threads_init</link></methodname>
 	<methodparam></methodparam>
@@ -966,6 +969,24 @@
 
     </refsect2>
 
+    <refsect2 id="function-gdk--lock">
+      <title>gtk.gdk.lock</title>
+
+      <programlisting><synopsis language="python">
+	  <varname>gtk.gdk.lock</varname>
+	</synopsis></programlisting>
+
+      <para>
+	The <varname>gtk.gdk.lock</varname> constant is a context manager that calls
+	<link linkend="function-gdk--threads-enter"><function>gtk.gdk.threads_enter</function></link>
+	and <link linkend="function-gdk--threads-leave"><function>gtk.gdk.threads_leave</function></link>
+	in its <function>__enter__</function> and <function>__exit__</function> methods
+	correspondingly. It is intended to be used in <literal>with</literal> statement,
+	new in Python 2.5. Read statement description for details.
+      </para>
+
+    </refsect2>
+
     <refsect2 id="function-gdk--threads-init">
       <title>gtk.gdk.threads_init</title>
 

Modified: trunk/gtk/__init__.py
==============================================================================
--- trunk/gtk/__init__.py	(original)
+++ trunk/gtk/__init__.py	Mon Sep  8 21:05:26 2008
@@ -90,6 +90,13 @@
 gdk.INPUT_WRITE     = _gobject.IO_OUT | _gobject.IO_HUP
 gdk.INPUT_EXCEPTION = _gobject.IO_PRI
 
+# Python 2.5+ context manager, usable through 'with' keyword.
+class _Lock(object):
+    __enter__ = gdk.threads_enter
+    def __exit__(*ignored):
+        gdk.threads_leave()
+gdk.lock = _Lock()
+
 # old names compatibility ...
 idle_add       = _Deprecated(_gobject, 'idle_add', 'idle_add', 'gobject')
 idle_remove    = _Deprecated(_gobject, 'source_remove', 'idle_remove', 'gobject')
@@ -125,13 +132,13 @@
 gdk.Warning = Warning
 
 # We don't want to export this
-del _Deprecated, _DeprecatedConstant, _gobject, _init
+del _Deprecated, _DeprecatedConstant, _gobject, _init, _Lock
 
 # Do this as late as possible, so programs like pyflakes can check
 # everything above
 from gtk._gtk import *
 
-# # For testing, so you can just turn of dynamicnamespace in gtk.override
+# # For testing, so you can just turn off dynamicnamespace in gtk.override
 # if hasattr(_gtk, '_get_symbol_names'):
 #     import gtk
 #     ns = LazyNamespace(_gtk, locals())
@@ -139,4 +146,3 @@
 #     ns.add_submodule('_gtk', 'gtk._gtk')
 #     sys.modules['gtk'] = ns
 #     sys.modules['gtk.glade'] = LazyModule('_glade', {})
-



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