mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-02-24 08:39:59 -05:00
restore BrozzlerWorker built-in support for managing its own thread
This commit is contained in:
parent
70b67942a5
commit
c2704b18be
@ -109,6 +109,9 @@ class BrozzlerWorker:
|
||||
self._browsing_threads = set()
|
||||
self._browsing_threads_lock = threading.Lock()
|
||||
|
||||
self._thread = None
|
||||
self._start_stop_lock = threading.Lock()
|
||||
|
||||
def _proxy(self, site):
|
||||
if site.proxy:
|
||||
return site.proxy
|
||||
@ -458,3 +461,28 @@ class BrozzlerWorker:
|
||||
for th in thredz:
|
||||
th.join()
|
||||
|
||||
def start(self):
|
||||
with self._start_stop_lock:
|
||||
if self._thread:
|
||||
self.logger.warn(
|
||||
'ignoring start request because self._thread is '
|
||||
'not None')
|
||||
return
|
||||
self._thread = threading.Thread(
|
||||
target=self.run, name="BrozzlerWorker")
|
||||
self._thread.start()
|
||||
|
||||
def shutdown_now(self):
|
||||
self.stop()
|
||||
|
||||
def stop(self):
|
||||
with self._start_stop_lock:
|
||||
if self._thread and self._thread.is_alive():
|
||||
self.logger.info("brozzler worker shutting down")
|
||||
brozzler.thread_raise(self._thread, brozzler.ShutdownRequested)
|
||||
self._thread.join()
|
||||
self._thread = None
|
||||
|
||||
def is_alive(self):
|
||||
return self._thread and self._thread.is_alive()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user