2018-01-03 08:39:30 +00:00
|
|
|
from senpy import AnalysisPlugin
|
2018-01-01 12:13:17 +00:00
|
|
|
|
|
|
|
import multiprocessing
|
|
|
|
|
|
|
|
|
|
|
|
def _train(process_number):
|
|
|
|
return process_number
|
|
|
|
|
|
|
|
|
2018-01-03 08:39:30 +00:00
|
|
|
class Async(AnalysisPlugin):
|
|
|
|
'''An example of an asynchronous module'''
|
|
|
|
author = '@balkian'
|
|
|
|
version = '0.2'
|
|
|
|
async = True
|
|
|
|
|
2018-01-01 12:13:17 +00:00
|
|
|
def _do_async(self, num_processes):
|
|
|
|
pool = multiprocessing.Pool(processes=num_processes)
|
2018-01-03 08:39:30 +00:00
|
|
|
values = sorted(pool.map(_train, range(num_processes)))
|
2018-01-01 12:13:17 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-01-03 08:39:30 +00:00
|
|
|
test_cases = [
|
|
|
|
{
|
|
|
|
'input': 'any',
|
|
|
|
'expected': {
|
|
|
|
'async_values': [0, 1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|