Total Complexity | 7 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 11 | ||
Bugs | 0 | Features | 1 |
1 | import asyncio |
||
12 | class LoaferManager: |
||
13 | |||
14 | def __init__(self, routes, consumers, runner=None): |
||
15 | self.runner = runner or LoaferRunner(on_stop_callback=self.on_loop__stop) |
||
16 | self.routes = routes |
||
17 | self.consumers = consumers |
||
18 | |||
19 | @cached_property |
||
20 | def dispatcher(self): |
||
21 | return LoaferDispatcher(self.routes, self.consumers) |
||
22 | |||
23 | def run(self, forever=True): |
||
24 | self._future = asyncio.gather(self.dispatcher.dispatch_providers()) |
||
25 | self._future.add_done_callback(self.on_future__errors) |
||
26 | self.runner.start(self._future, run_forever=forever) |
||
27 | |||
28 | # |
||
29 | # Callbacks |
||
30 | # |
||
31 | |||
32 | def on_future__errors(self, future): |
||
33 | exc = future.exception() |
||
34 | # Unhandled errors crashes the event loop execution |
||
35 | if isinstance(exc, BaseException): |
||
36 | logger.critical('Fatal error caught: {!r}'.format(exc)) |
||
37 | self.runner.stop() |
||
38 | |||
39 | def on_loop__stop(self, *args, **kwargs): |
||
40 | logger.debug('Stopping consumers ...') |
||
41 | self.dispatcher.stop_providers() |
||
42 | |||
43 | if hasattr(self, '_future'): |
||
44 | logger.debug('Cancel schedulled operations ...') |
||
45 | self._future.cancel() |
||
46 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.