Commit 8918947d by rfkelly0

osfs.watch_inotify: make background thread friendlier to interpreter shutdown

parent 547e5f54
...@@ -43,6 +43,7 @@ class OSFSWatchMixin(WatchableFSMixin): ...@@ -43,6 +43,7 @@ class OSFSWatchMixin(WatchableFSMixin):
wt = self.__watch_thread wt = self.__watch_thread
if wt is not None and not wt.watchers: if wt is not None and not wt.watchers:
wt.stop() wt.stop()
wt.join()
OSFSWatchMixin.__watch_thread = None OSFSWatchMixin.__watch_thread = None
finally: finally:
self.__watch_lock.release() self.__watch_lock.release()
...@@ -225,17 +226,22 @@ class SharedThreadedNotifier(threading.Thread): ...@@ -225,17 +226,22 @@ class SharedThreadedNotifier(threading.Thread):
self._poller.unregister(fd) self._poller.unregister(fd)
def run(self): def run(self):
# Grab some attributes of the select module, so they're available
# even when shutting down the interpreter.
_select_error = select.error
_select_POLLIN = select.POLLIN
# Loop until stopped, dispatching to individual notifiers.
self.running = True self.running = True
while self.running: while self.running:
try: try:
ready_fds = self._poller.poll() ready_fds = self._poller.poll()
except select.error, e: except _select_error, e:
if e[0] != errno.EINTR: if e[0] != errno.EINTR:
raise raise
else: else:
for (fd,event) in ready_fds: for (fd,event) in ready_fds:
# Ignore all events other than "input ready". # Ignore all events other than "input ready".
if not event & select.POLLIN: if not event & _select_POLLIN:
continue continue
# For signals on our internal pipe, just read and discard. # For signals on our internal pipe, just read and discard.
if fd == self._pipe_r: if fd == self._pipe_r:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment