aio-libs / aiohttp-devtools

dev tools for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autoreload doesn't work

amirouche opened this issue · comments

I've setup a project with:

  • aiohttp devtools: 0.6.4
  • aiohttp version: 2.3.6
  • python version: 3.6
  • Platform: Ubuntu 17.10 Artful

The autoreload doesn't work, it doesn't detect the changes of the backend side. I use the following adev command:

$ DEBUG=DEBUG adev runserver --no-debug-toolbar datalibrary/api.py
[12:19:17] pre-check enabled, checking app factory
2017-12-19 12:19:17,078 [6652] INFO     datalibrary.api: boot datalibrary-api server
2017-12-19 12:19:17,079 [6652] DEBUG    datalibrary.api: setup asyncpg, using postgres://datalibrary:datalibrary@localhost:5432/datalibrary
[12:19:17] Starting aux server at http://localhost:8001 ◆
2017-12-19 12:19:17,093 [6652] INFO     adev.server.dft: Starting aux server at http://localhost:8001 ◆
[12:19:17] Starting dev server at http://localhost:8000 ●
2017-12-19 12:19:17,094 [6652] INFO     adev.server.dft: Starting dev server at http://localhost:8000 ●
2017-12-19 12:19:17,102 [6652] DEBUG    watchgod.main: time=1ms files=40 changes=0
2017-12-19 12:19:17,502 [6652] DEBUG    watchgod.main: time=1ms files=40 changes=0
2017-12-19 12:19:17,768 [6678] INFO     datalibrary.api: boot datalibrary-api server
2017-12-19 12:19:17,770 [6678] DEBUG    datalibrary.api: setup asyncpg, using postgres://datalibrary:datalibrary@localhost:5432/datalibrary
2017-12-19 12:19:17,904 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:18,305 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:18,706 [6652] DEBUG    watchgod.main: time=3ms files=40 changes=0
2017-12-19 12:19:19,107 [6652] DEBUG    watchgod.main: time=3ms files=40 changes=0
2017-12-19 12:19:19,507 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:19,909 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:20,309 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:20,711 [6652] DEBUG    watchgod.main: time=3ms files=40 changes=0
2017-12-19 12:19:21,111 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:21,512 [6652] DEBUG    watchgod.main: time=3ms files=40 changes=0
2017-12-19 12:19:21,913 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
2017-12-19 12:19:22,314 [6652] DEBUG    watchgod.main: time=3ms files=40 changes=0
2017-12-19 12:19:22,715 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0

The watchgod is kicking and then when a file changes it stops...

Here is the traceback when I hit Ctrl+C:

2017-12-19 12:19:22,715 [6652] DEBUG    watchgod.main: time=2ms files=40 changes=0
^C[12:20:23] shutting down server...
2017-12-19 12:20:23,377 [6652] INFO     adev.server.dft: shutting down server...
2017-12-19 12:20:23,464 [6652] CRITICAL root: Traceback (most recent call last):
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/bin/adev", line 11, in <module>
    sys.exit(cli())
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp_devtools/cli.py", line 88, in runserver
    run_app(*_runserver(**active_config))
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp_devtools/runserver/main.py", line 26, in run_app
    loop.run_until_complete(app.shutdown())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp/web.py", line 272, in shutdown
    yield from self.on_shutdown.send(self)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp/signals.py", line 51, in send
    yield from self._send(*args, **kwargs)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp/signals.py", line 17, in _send
    yield from res
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp_devtools/runserver/watch.py", line 108, in close
    await super().close()
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp_devtools/runserver/watch.py", line 32, in close
    self._task.result()
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/aiohttp_devtools/runserver/watch.py", line 48, in _run
    async for changes in self._awatch:
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/watchgod/main.py", line 89, in __anext__
    changes = await self._loop.run_in_executor(None, self._w.check)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/watchgod/watcher.py", line 43, in check
    self._walk(str(self.root_path), changes, new_files)
  File "/home/amirouche/.local/share/virtualenvs/west2-bifHViav/lib/python3.6/site-packages/watchgod/watcher.py", line 32, in _walk
    mtime = entry.stat().st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/home/amirouche/src/namr/datalibrary/west2/datalibrary/.#api.py'

2017-12-19 12:20:23,497 [6652] ERROR    asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7ff6416b6a58>
(west2-bifHViav) 

So emacs creates a temporary file that is then detected by watchgod but disappears quickly.

Here the fix in watchgod/watcher.py", line 32`:


    def _walk(self, dir_path, changes, new_files):
        for entry in os.scandir(dir_path):
            if entry.is_dir():
                if self.should_watch_dir(entry):
                    self._walk(entry.path, changes, new_files)
            elif self.should_watch_file(entry):
                try:
                    mtime = entry.stat().st_mtime
                except Exception:
                    continue
                else:
                    new_files[entry.path] = mtime
                    old_mtime = self.files.get(entry.path)
                    if not old_mtime:
                        changes.add((Change.added, entry.path))
                    elif old_mtime != mtime:
                        changes.add((Change.modified, entry.path))

What's the path of the file you're changing, and the temporary file?

I can't see the change there, maybe create a pr to watchgod.

Indeed it seems more like a bug in watchgod. sorry for the noise.

Watchgod is my problem too so no problem.