[Python-3000-checkins] r66161 - in python/branches/py3k: Lib/multiprocessing/managers.py

jesse.noller python-3000-checkins at python.org
Tue Sep 2 21:12:20 CEST 2008


Author: jesse.noller
Date: Tue Sep  2 21:12:20 2008
New Revision: 66161

Log:
Merge r66115 forward to py3k, resolves issue3419


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/multiprocessing/managers.py

Modified: python/branches/py3k/Lib/multiprocessing/managers.py
==============================================================================
--- python/branches/py3k/Lib/multiprocessing/managers.py	(original)
+++ python/branches/py3k/Lib/multiprocessing/managers.py	Tue Sep  2 21:12:20 2008
@@ -378,7 +378,13 @@
 
             self.id_to_obj[ident] = (obj, set(exposed), method_to_typeid)
             if ident not in self.id_to_refcount:
-                self.id_to_refcount[ident] = None
+                self.id_to_refcount[ident] = 0
+            # increment the reference count immediately, to avoid
+            # this object being garbage collected before a Proxy
+            # object for it can be created.  The caller of create()
+            # is responsible for doing a decref once the Proxy object
+            # has been created.
+            self.incref(c, ident)
             return ident, tuple(exposed)
         finally:
             self.mutex.release()
@@ -400,11 +406,7 @@
     def incref(self, c, ident):
         self.mutex.acquire()
         try:
-            try:
-                self.id_to_refcount[ident] += 1
-            except TypeError:
-                assert self.id_to_refcount[ident] is None
-                self.id_to_refcount[ident] = 1
+            self.id_to_refcount[ident] += 1
         finally:
             self.mutex.release()
 
@@ -641,6 +643,8 @@
                     token, self._serializer, manager=self,
                     authkey=self._authkey, exposed=exp
                     )
+                conn = self._Client(token.address, authkey=self._authkey)
+                dispatch(conn, None, 'decref', (token.id,))
                 return proxy
             temp.__name__ = typeid
             setattr(cls, typeid, temp)
@@ -733,10 +737,13 @@
         elif kind == '#PROXY':
             exposed, token = result
             proxytype = self._manager._registry[token.typeid][-1]
-            return proxytype(
+            proxy = proxytype(
                 token, self._serializer, manager=self._manager,
                 authkey=self._authkey, exposed=exposed
                 )
+            conn = self._Client(token.address, authkey=self._authkey)
+            dispatch(conn, None, 'decref', (token.id,))
+            return proxy
         raise convert_to_error(kind, result)
 
     def _getvalue(self):


More information about the Python-3000-checkins mailing list