Skip to content

Commit

Permalink
async exception handling and _start kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Jul 20, 2019
1 parent ba34c58 commit 77364e6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion atasker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = "Altertech Group, http://www.altertech.com/"
__copyright__ = "Copyright (C) 2018-2019 Altertech Group"
__license__ = "Apache License 2.0"
__version__ = "0.2.6"
__version__ = "0.2.7"

from atasker.supervisor import TaskSupervisor
from atasker.supervisor import TASK_LOW
Expand Down
2 changes: 1 addition & 1 deletion atasker/f.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = "Altertech Group, http://www.altertech.com/"
__copyright__ = "Copyright (C) 2018-2019 Altertech Group"
__license__ = "Apache License 2.0"
__version__ = "0.2.6"
__version__ = "0.2.7"

import traceback
import threading
Expand Down
2 changes: 1 addition & 1 deletion atasker/supervisor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = "Altertech Group, http://www.altertech.com/"
__copyright__ = "Copyright (C) 2018-2019 Altertech Group"
__license__ = "Apache License 2.0"
__version__ = "0.2.6"
__version__ = "0.2.7"

import threading
import multiprocessing
Expand Down
2 changes: 1 addition & 1 deletion atasker/threads.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = "Altertech Group, http://www.altertech.com/"
__copyright__ = "Copyright (C) 2018-2019 Altertech Group"
__license__ = "Apache License 2.0"
__version__ = "0.2.6"
__version__ = "0.2.7"

import threading
import time
Expand Down
26 changes: 17 additions & 9 deletions atasker/workers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = "Altertech Group, http://www.altertech.com/"
__copyright__ = "Copyright (C) 2018-2019 Altertech Group"
__license__ = "Apache License 2.0"
__version__ = "0.2.6"
__version__ = "0.2.7"

import threading
import logging
Expand Down Expand Up @@ -119,7 +119,7 @@ def start(self, *args, **kwargs):
kw['o'] = self.o
self._task_args = args
self._task_kwargs = kw
self._start()
self._start(*args, **kwargs)
while not self._started:
time.sleep(self.poll_delay)
self.after_start()
Expand Down Expand Up @@ -258,11 +258,15 @@ def _run(self, *args):
self._send_executor_stop_event()

async def _run_coroutine(self, *args, **kwargs):
if await self.run(*(args + self._task_args), **
self._task_kwargs) is False:
self._abort()
self._current_executor = None
self._send_executor_stop_event()
try:
if await self.run(*(args + self._task_args), **
self._task_kwargs) is False:
self._abort()
except Exception as e:
self.error(e)
finally:
self._current_executor = None
self._send_executor_stop_event()

def _send_executor_stop_event(self):
asyncio.run_coroutine_threadsafe(
Expand All @@ -280,8 +284,12 @@ async def launch_executor(self, *args, **kwargs):
self._run_coroutine(*args), loop=self.executor_loop)
return True
else:
result = await self.run(*(args + self._task_args),
**self._task_kwargs)
try:
result = await self.run(*(args + self._task_args),
**self._task_kwargs)
except Exception as e:
self.error(e)
result = None
self._current_executor = None
return result is not False and self._active
elif self._run_in_mp:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.6"
__version__ = "0.2.7"

import setuptools

Expand Down

0 comments on commit 77364e6

Please sign in to comment.