asyncplugin.py 572 Bytes
Newer Older
1
2
3
4
5
from senpy.plugins import AnalysisPlugin

import multiprocessing


6
7
8
def _train(process_number):
    return process_number

9

10
class AsyncPlugin(AnalysisPlugin):
11
    def _do_async(self, num_processes):
12
13
14
        pool = multiprocessing.Pool(processes=num_processes)
        values = pool.map(_train, range(num_processes))

15
16
17
18
19
20
21
22
23
        return values

    def activate(self):
        self.value = self._do_async(4)

    def analyse_entry(self, entry, params):
        values = self._do_async(2)
        entry.async_values = values
        yield entry
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
24
25
26

    def test(self):
        pass