diff build/bdist.linux-x86_64/egg/CHAP/async.py @ 0:cbbe42422d56 draft

planemo upload for repository https://github.com/CHESSComputing/ChessAnalysisPipeline/tree/galaxy commit 1401a7e1ae007a6bda260d147f9b879e789b73e0-dirty
author kls286
date Tue, 28 Mar 2023 15:07:30 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build/bdist.linux-x86_64/egg/CHAP/async.py	Tue Mar 28 15:07:30 2023 +0000
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+#-*- coding: utf-8 -*-
+#pylint: disable=
+"""
+File       : async.py
+Author     : Valentin Kuznetsov <vkuznet AT gmail dot com>
+Description: AsyncProcessor module
+"""
+
+# system modules
+import asyncio
+
+# local modules
+from CHAP.processor import Processor, PrintProcessor
+
+
+async def task(mgr, doc):
+    """
+    Process given data using provided task manager
+    """
+    return mgr.process(doc)
+
+
+async def executeTasks(mgr, docs):
+    """
+    Process given set of documents using provided task manager
+    """
+    coRoutines = [task(mgr, d) for d in docs]
+    await asyncio.gather(*coRoutines)
+
+
+class AsyncProcessor(Processor):
+    """
+    AsyncProcesor process given data via asyncio module
+    """
+    def __init__(self, mgr):
+        super().__init__()
+        self.mgr = mgr
+
+    def _process(self, docs):
+        """
+        Internal method to process given data documents
+        """
+        asyncio.run(executeTasks(self.mgr, docs))
+
+def example():
+    """
+    Helper function to demonstrate usage of AsyncProcessor
+    """
+    docs = [1,2,3]
+    mgr = PrintProcessor()
+    processor = AsyncProcessor(mgr)
+    processor.process(docs)
+
+if __name__ == '__main__':
+    example()