| 877 | |
| 878 | @staticmethod |
| 879 | def _decref(token, serial, authkey, state, tls, idset, _Client): |
| 880 | idset.discard(serial) |
| 881 | |
| 882 | # check whether manager is still alive |
| 883 | if state is None or state.value == State.STARTED: |
| 884 | # tell manager this process no longer cares about referent |
| 885 | try: |
| 886 | util.debug('DECREF %r', token.id) |
| 887 | conn = _Client(token.address, authkey=authkey) |
| 888 | dispatch(conn, None, 'decref', (token.id,)) |
| 889 | except Exception as e: |
| 890 | util.debug('... decref failed %s', e) |
| 891 | |
| 892 | else: |
| 893 | util.debug('DECREF %r -- manager already shutdown', token.id) |
| 894 | |
| 895 | # check whether we can close this thread's connection because |
| 896 | # the process owns no more references to objects for this manager |
| 897 | if not idset and hasattr(tls, 'connection'): |
| 898 | util.debug('thread %r has no more proxies so closing conn', |
| 899 | threading.current_thread().name) |
| 900 | tls.connection.close() |
| 901 | del tls.connection |
| 902 | |
| 903 | def _after_fork(self): |
| 904 | self._manager = None |