From 4727c8c9b8093694114d0d5b8cc1e6bb6fc22b06 Mon Sep 17 00:00:00 2001 From: Adrien Delle Cave Date: Thu, 22 Apr 2021 17:44:08 +0200 Subject: [PATCH] Reviewed sonicprobe.libs.workerpool. --- CHANGELOG | 6 ++++ RELEASE | 2 +- VERSION | 2 +- setup.yml | 4 +-- sonicprobe/libs/workerpool.py | 58 +++++++++++++++++++---------------- 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a078033..b84cc88 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +python-sonicprobe (0.3.41) unstable; urgency=medium + + * Reviewed sonicprobe.libs.workerpool. + + -- Adrien DELLE CAVE (Decryptus) Thu, 22 Apr 2021 17:42:54 +0200 + python-sonicprobe (0.3.40) unstable; urgency=medium * Reviewed requirements. diff --git a/RELEASE b/RELEASE index a02af24..b463c01 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -0.3.40 +0.3.41 diff --git a/VERSION b/VERSION index a02af24..b463c01 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.40 +0.3.41 diff --git a/setup.yml b/setup.yml index cc5ed1a..2ea7505 100644 --- a/setup.yml +++ b/setup.yml @@ -4,8 +4,8 @@ description: sonicprobe author: Adrien Delle Cave author_email: pypi@doowan.net copyright: '2021 Adrien Delle Cave' -release: '0.3.40' -version: '0.3.40' +release: '0.3.41' +version: '0.3.41' license: License GPL-3 url: https://github.com/decryptus/sonicprobe python_requires: diff --git a/sonicprobe/libs/workerpool.py b/sonicprobe/libs/workerpool.py index 0d392cc..7e51869 100644 --- a/sonicprobe/libs/workerpool.py +++ b/sonicprobe/libs/workerpool.py @@ -100,6 +100,8 @@ def run(self): cb(ret) except Exception as e: LOG.exception("unexpected error: %r", e) + except SystemExit as e: + LOG.error("system exit: %r", e) finally: if complete: complete(ret) @@ -231,43 +233,47 @@ def add(self, nb = 1, name = None, xid = None): w.setName(self.get_name(xid, name)) w.start() - def run(self, target, callback = None, name = None, complete = None, qpriority = None, *args, **kargs): - """ - Start task. - @target: callable to run with *args and **kargs arguments. - @callback: callable executed after target. - @name: thread name - @complete: complete executed after target in finally - @qpriority: priority for PriorityQueue - """ + def _run(self, target, _callback_ = None, _name_ = None, _complete_ = None, _qpriority_ = None, *args, **kwargs): self.count_lock.acquire() if not self.workers: self.count_lock.release() - self.add(name = name) + self.add(name = _name_) else: self.count_lock.release() if not self.is_qpriority: - self.tasks.put((target, callback, name, complete, args, kargs)) + self.tasks.put((target, _callback_, _name_, _complete_, args, kwargs)) return - if qpriority is None: - qpriority = time.time() - self.tasks.put((qpriority, (target, callback, name, complete, args, kargs))) + if _qpriority_ is None: + _qpriority_ = time.time() + self.tasks.put((_qpriority_, (target, _callback_, _name_, _complete_, args, kwargs))) + + def run(self, target, callback = None, name = None, complete = None, qpriority = None, *args, **kargs): + """ + Start task. + @target: callable to run with *args and **kargs arguments. + @callback: callable executed after target. + @name: thread name + @complete: complete executed after target in finally + @qpriority: priority for PriorityQueue + """ + self._run(target, + _callback_ = callback, + _name_ = name, + _complete_ = complete, + _qpriority_ = qpriority, + *args, + **kargs) def run_args(self, target, *args, **kwargs): - callback = kwargs.pop('_callback_', None) - name = kwargs.pop('_name_', None) - complete = kwargs.pop('_complete_', None) - qpriority = kwargs.pop('_qpriority_', None) - - self.run(target = target, - callback = callback, - name = name, - complete = complete, - qpriority = qpriority, - *args, - **kwargs) + self._run(target = target, + _callback_ = kwargs.pop('_callback_', None), + _name_ = kwargs.pop('_name_', None), + _complete_ = kwargs.pop('_complete_', None), + _qpriority_ = kwargs.pop('_qpriority_', None), + *args, + **kwargs) def killall(self, wait = None): """