@@ -759,22 +759,29 @@ class BaseProxy(object):
759759 _address_to_local = {}
760760 _mutex = util .ForkAwareThreadLock ()
761761
762+ # Each instance gets a `_serial` number. Unlike `id(...)`, this number
763+ # is never reused.
764+ _next_serial = 1
765+
762766 def __init__ (self , token , serializer , manager = None ,
763767 authkey = None , exposed = None , incref = True , manager_owned = False ):
764768 with BaseProxy ._mutex :
765- tls_idset = BaseProxy ._address_to_local .get (token .address , None )
766- if tls_idset is None :
767- tls_idset = util .ForkAwareLocal (), ProcessLocalSet ()
768- BaseProxy ._address_to_local [token .address ] = tls_idset
769+ tls_serials = BaseProxy ._address_to_local .get (token .address , None )
770+ if tls_serials is None :
771+ tls_serials = util .ForkAwareLocal (), ProcessLocalSet ()
772+ BaseProxy ._address_to_local [token .address ] = tls_serials
773+
774+ self ._serial = BaseProxy ._next_serial
775+ BaseProxy ._next_serial += 1
769776
770777 # self._tls is used to record the connection used by this
771778 # thread to communicate with the manager at token.address
772- self ._tls = tls_idset [0 ]
779+ self ._tls = tls_serials [0 ]
773780
774- # self._idset is used to record the identities of all shared
775- # objects for which the current process owns references and
781+ # self._all_serials is a set used to record the identities of all
782+ # shared objects for which the current process owns references and
776783 # which are in the manager at token.address
777- self ._idset = tls_idset [1 ]
784+ self ._all_serials = tls_serials [1 ]
778785
779786 self ._token = token
780787 self ._id = self ._token .id
@@ -857,20 +864,20 @@ def _incref(self):
857864 dispatch (conn , None , 'incref' , (self ._id ,))
858865 util .debug ('INCREF %r' , self ._token .id )
859866
860- self ._idset .add (self ._id )
867+ self ._all_serials .add (self ._serial )
861868
862869 state = self ._manager and self ._manager ._state
863870
864871 self ._close = util .Finalize (
865872 self , BaseProxy ._decref ,
866- args = (self ._token , self ._authkey , state ,
867- self ._tls , self ._idset , self ._Client ),
873+ args = (self ._token , self ._serial , self . _authkey , state ,
874+ self ._tls , self ._all_serials , self ._Client ),
868875 exitpriority = 10
869876 )
870877
871878 @staticmethod
872- def _decref (token , authkey , state , tls , idset , _Client ):
873- idset .discard (token . id )
879+ def _decref (token , serial , authkey , state , tls , idset , _Client ):
880+ idset .discard (serial )
874881
875882 # check whether manager is still alive
876883 if state is None or state .value == State .STARTED :
0 commit comments