diff --git a/direct/src/distributed/ConnectionRepository.py b/direct/src/distributed/ConnectionRepository.py index a9972ab79f..b5c4324e89 100644 --- a/direct/src/distributed/ConnectionRepository.py +++ b/direct/src/distributed/ConnectionRepository.py @@ -51,7 +51,9 @@ class ConnectionRepository( DoInterestManager.__init__(self) DoCollectionManager.__init__(self) self.setPythonRepository(self) - + + base.finalExitCallbacks.append(self.shutdown) + self.config = config if self.config.GetBool('verbose-repository'): @@ -591,6 +593,7 @@ class ConnectionRepository( def readerPollUntilEmpty(self, task): while self.readerPollOnce(): pass + Thread.forceYield() return Task.cont def readerPollOnce(self): diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index bbde55ed36..6c38e5536b 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -665,6 +665,22 @@ disconnect() { _simulated_disconnect = false; } +//////////////////////////////////////////////////////////////////// +// Function: CConnectionRepository::shutdown +// Access: Published +// Description: May be called at application shutdown to ensure all +// threads are cleaned up. +//////////////////////////////////////////////////////////////////// +void CConnectionRepository:: +shutdown() { + disconnect(); + + #ifdef HAVE_NET + _cw.shutdown(); + _qcr.shutdown(); + #endif // HAVE_NET +} + //////////////////////////////////////////////////////////////////// // Function: CConnectionRepository::do_check_datagram // Access: Private diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index 13bfbf853a..9efa85ceba 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -144,6 +144,7 @@ PUBLISHED: bool flush(); void disconnect(); + void shutdown(); INLINE void set_simulated_disconnect(bool simulated_disconnect); INLINE bool get_simulated_disconnect() const; diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index ba098b742a..4cfa04d134 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -429,6 +429,9 @@ class ShowBase(DirectObject.DirectObject): This function is designed to be safe to call multiple times.""" + for cb in self.finalExitCallbacks: + cb() + # [gjeon] restore sticky key settings if self.config.GetBool('disable-sticky-keys', 0): allowAccessibilityShortcutKeys(True) @@ -457,9 +460,6 @@ class ShowBase(DirectObject.DirectObject): vfs = VirtualFileSystem.getGlobalPtr() vfs.unmountAll() - - for cb in self.finalExitCallbacks: - cb() def exitfunc(self):