aiogear
Advanced tools
| Metadata-Version: 1.1 | ||
| Name: aiogear | ||
| Version: 0.1.3 | ||
| Version: 0.1.4 | ||
| Summary: Asynchronous gearman protocol based on asyncio | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/sardok/aiogear |
+27
-19
@@ -19,6 +19,7 @@ import asyncio | ||
| self.transport = None | ||
| self.task = None | ||
| self.main_task = None | ||
| self.functions = OrderedDict() | ||
| self.running = WeakValueDictionary() | ||
| self.waiters = [] | ||
| self.shutting_down = False | ||
@@ -52,3 +53,3 @@ grab_mapping = { | ||
| self.can_do(fname) | ||
| self.task = self.get_task() | ||
| self.main_task = self.get_task(self.run()) | ||
@@ -58,8 +59,8 @@ def connection_lost(self, exc): | ||
| def get_task(self): | ||
| return asyncio.Task(self.run()) | ||
| def get_task(self, coro): | ||
| return asyncio.ensure_future(coro, loop=self.loop) | ||
| async def run(self,): | ||
| no_job = NoJob() | ||
| while True: | ||
| while not self.shutting_down: | ||
| self.pre_sleep() | ||
@@ -84,3 +85,3 @@ await self.wait_for(Type.NOOP) | ||
| if asyncio.iscoroutine(result_or_coro): | ||
| task = asyncio.ensure_future(result_or_coro, loop=self.loop) | ||
| task = self.get_task(result_or_coro) | ||
| self.running[job_info.handle] = task | ||
@@ -94,2 +95,4 @@ result = await task | ||
| self.work_exception(job_info.handle, str(ex)) | ||
| finally: | ||
| self.running.pop(job_info.handle, None) | ||
@@ -99,16 +102,21 @@ except AttributeError: | ||
| async def shutdown(self): | ||
| logger.debug('Shutting down worker ...') | ||
| async def cancel_and_wait(tasks): | ||
| if not tasks: | ||
| return | ||
| for task in tasks: | ||
| task.cancel() | ||
| try: | ||
| await asyncio.wait(tasks, loop=self.loop) | ||
| except asyncio.CancelledError: | ||
| pass | ||
| async def shutdown(self, graceful=False): | ||
| logger.debug('Shutting down worker {}gracefully...'.format('' if graceful else 'un')) | ||
| self.shutting_down = True | ||
| sub_tasks = list(self.running.values()) | ||
| if graceful: | ||
| if sub_tasks: | ||
| await asyncio.wait(sub_tasks, loop=self.loop) | ||
| else: | ||
| async def cancel_and_wait(tasks): | ||
| for task in tasks: | ||
| task.cancel() | ||
| try: | ||
| await asyncio.wait(tasks, loop=self.loop) | ||
| except asyncio.CancelledError: | ||
| pass | ||
| if sub_tasks: | ||
| await cancel_and_wait(sub_tasks) | ||
| self.main_task.cancel() | ||
| await cancel_and_wait(list(self.running.values())) | ||
| await cancel_and_wait([self.task]) | ||
| if self.transport: | ||
@@ -115,0 +123,0 @@ self.transport.close() |
+1
-1
| Metadata-Version: 1.1 | ||
| Name: aiogear | ||
| Version: 0.1.3 | ||
| Version: 0.1.4 | ||
| Summary: Asynchronous gearman protocol based on asyncio | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/sardok/aiogear |
+1
-1
@@ -5,3 +5,3 @@ from setuptools import setup | ||
| name='aiogear', | ||
| version='0.1.3', | ||
| version='0.1.4', | ||
| author='Sinan Nalkaya', | ||
@@ -8,0 +8,0 @@ author_email='sardok@gmail.com', |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
18119
2.31%425
1.92%