[Zodb-checkins] CVS: ZODB3/ThreadedAsync - LoopCallback.py:1.7

Barry Warsaw barry@wooz.org
Thu, 12 Dec 2002 14:48:06 -0500

Update of /cvs-repository/ZODB3/ThreadedAsync
In directory cvs.zope.org:/tmp/cvs-serv28670

Modified Files:
Log Message:
Remove the direct rebinding of asyncore.loop to this module's loop()
function.  This was a nasty decoy (am I using that term correctly?

Because we're worried about backward compatibility, for now we'll
rebind asyncore.loop() to a function that prints a warning and then
calls loop().  Eventually we'll take this away so you have to call
ThreadedAsync.loop() explicitly.

=== ZODB3/ThreadedAsync/LoopCallback.py 1.6 => 1.7 ===
--- ZODB3/ThreadedAsync/LoopCallback.py:1.6	Tue Nov  5 14:31:21 2002
+++ ZODB3/ThreadedAsync/LoopCallback.py	Thu Dec 12 14:48:06 2002
@@ -24,10 +24,6 @@
 register_loop_callback() to register interest.  When the mainloop
 thread calls loop(), each registered callback will be called with the
 socket map as its first argument.
-This module rebinds loop() in the asyncore module; i.e. once this
-module is imported, any client of the asyncore module will get
-ThreadedAsync.loop() when it calls asyncore.loop().
 __version__ = '$Revision$'[11:-2]
@@ -150,11 +146,23 @@
         poll_fun(timeout, map)
-# Woo hoo!
-asyncore.loop = loop
-# What the heck did we just do?
+# This module used to do something evil -- it rebound asyncore.loop to the
+# above loop() function.  What was evil about this is that if you added some
+# debugging to asyncore.loop, you'd spend 6 hours debugging why your debugging
+# code wasn't called!
-# Well, the thing is, we want to work with other asyncore aware
-# code. In particular, we don't necessarily want to make someone
-# import this module just to start or loop.
+# Code should instead explicitly call ThreadedAsync.loop() instead of
+# asyncore.loop().  Most of ZODB has been fixed, but ripping this out may
+# break 3rd party code.  So we'll issue a warning and let it continue -- for
+# now.
+def deprecated_loop(*args, **kws):
+    import warnings
+    warnings.warn("""\
+ThreadedAsync.loop() called through sneaky asyncore.loop() rebinding.
+You should change your code to call ThreadedAsync.loop() explicitly.""",
+                  DeprecationWarning)
+    loop(*args, **kws)
+asyncore.loop = deprecated_loop