ask / mode

Python AsyncIO Services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to start example service.py

dchimeno opened this issue · comments

Starting example/service.py with debug=True

import mode

class MyService(mode.Service):

    async def on_started(self) -> None:
        self.log.info('Service started (hit ctrl+C to exit).')

    @mode.Service.task
    async def _background_task(self) -> None:
        print('BACKGROUND TASK STARTING')
        while not self.should_stop:
            await self.sleep(1.0)
            print('BACKGROUND SERVICE WAKING UP')


if __name__ == '__main__':
    mode.Worker(
        MyService(),
        debug=True,
        loglevel='INFO',
        logfile=None,  # stderr
).execute_from_commandline()
python app.py
[2018-08-08 16:21:05,376: ERROR]: [^Worker]: Error: TypeError('Use `self.add_context(ctx)` for non-async context')
Traceback (most recent call last):
  File "/path/python3.7/site-packages/mode/worker.py", line 189, in execute_from_commandline
    self.loop.run_until_complete(self.start())
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
    return future.result()
  File "/path/python3.7/site-packages/mode/worker.py", line 241, in start
    await super().start()
  File "/path/python3.7/site-packages/mode/services.py", line 657, in start
    await self._default_start()
  File "/path/python3.7/site-packages/mode/services.py", line 662, in _default_start
    await self._actually_start()
  File "/path/python3.7/site-packages/mode/services.py", line 668, in _actually_start
    await self.on_first_start()
  File "/path/python3.7/site-packages/mode/worker.py", line 118, in on_first_start
    await self.default_on_first_start()
  File "/path/python3.7/site-packages/mode/worker.py", line 124, in default_on_first_start
    await self._add_monitor()
  File "/path/python3.7/site-packages/mode/worker.py", line 254, in _add_monitor
    await self.add_async_context(monitor)
  File "/path/python3.7/site-packages/mode/services.py", line 525, in add_async_context
    'Use `self.add_context(ctx)` for non-async context')
TypeError: Use `self.add_context(ctx)` for non-async context

Versions

  • Python version 3.7.0
  • Mode version: 1.15.0
  • aiomonitor: aiomonitor 0.3.1
  • Operating system: Lastest Macos

This also happen in faust, version Faust 1.0.28 either with Python 3.6.5 and Python 3.7.0