Beispiel #1
0
def setup_zfs_events_process(middleware):
    set_thread_name('retrieve_zfs_events_thread')
    while True:
        try:
            parent_conn, child_conn = multiprocessing.Pipe(duplex=False)
            events_process = multiprocessing.Process(
                daemon=True,
                target=zfs_events,
                args=(child_conn, ),
                name='retrieve_zfs_events_process')
        except Exception as e:
            middleware.logger.error(
                'Failed to spawn process for retrieving ZFS events %s', str(e))
            time.sleep(3)
            continue

        try:
            events_process.start()
            while True:
                middleware.call_hook_sync('zfs.pool.events',
                                          data=parent_conn.recv())
        except Exception as e:
            if middleware.call_sync('system.state') != 'SHUTTING_DOWN':
                middleware.logger.error('Failed to retrieve ZFS events: %s',
                                        str(e))
            else:
                break

        time.sleep(1)
Beispiel #2
0
    def _target(self):
        osc.set_thread_name(self.name)
        try:
            while True:
                work_item = self.executor.get_work_item(self)
                if work_item is None:
                    return

                work_item.run()
                del work_item
        except Exception:
            logger.critical("Exception in worker", exc_info=True)
        finally:
            self.executor.remove_worker(self)
Beispiel #3
0
 def run(self):
     set_thread_name('ha_connection')
     retry = 5
     refused = False
     while True:
         try:
             self.connect_and_wait()
             refused = False
         except ConnectionRefusedError:
             if not refused:
                 logger.error(f'Persistent connection refused, retrying every {retry} seconds')
             refused = True
         except Exception:
             logger.error('Remote connection failed', exc_info=True)
             refused = False
         time.sleep(retry)
Beispiel #4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._initializer = set_thread_name('IoThread')

        # we set these to 21 or 33 respectively so that we
        # always have a 1 idle thread buffer when we check
        # the semaphore which should help prevent a non-fatal
        # race condition with the caller of this method
        # minimally we have 21 - 1 thread available
        # on large cpu count systems we set it to 33 - 1 (to match upstream)
        self._max_workers = 21 if ((cpu_count() or 1) + 4) < 32 else 33
Beispiel #5
0
 def run(self):
     osc.set_thread_name('ad_monitor_thread')
     try:
         self.read_messages()
     except Exception as e:
         self.logger.debug('Failed to run monitor thread %s', e, exc_info=True)