-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reload not working on non standard project structure #209
Comments
Just run across this too, if |
I have a application that monitor a system and running aiohttp at the same time. root
|- __main__.py
|- service.py
|- container.py
|- worker.py
|- http
|- app.py
|- action.py
|- asset
|- *.js
|- *.css
|- view
|- *.j2 The main.py will run all registered event loop ( not only aiohttp ) app.py from aiohttp_devtools import runserver
app = web.Application()
config = runserver.config.Config({
app_path="root/http"
root_path="root",
livereoload=True
})
runserver.serve.modify_main_app(app, config) worker.py from app import app
async def httpserver():
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, host, port)
await site.start()
async def other_long_task():
await long_task() main.py loop = asyncio.get_event_loop()
asyncio.ensure_future(httpserver())
asyncio.ensure_future(other_long_task())
loop.run_forever() With this approached all modified css js or template will be updated on next reload |
I don't think devtools was ever designed to be run like this. I think you should really just be using the commands (i.e. The aiohttp app should then be the single point of entry and manage everything else. For example, I have a 2nd (non-aiohttp) server in my project and for local development I run that in another process with code like: async def run_server(_app):
proc = await asyncio.create_subprocess_exec(path)
yield
if proc.returncode is None:
proc.terminate()
await proc.wait()
app.cleanup_ctx.append(run_server) Making your code this way will make it a lot more robust and will work with tools like aiohttp-devtools much better. |
Ok got it, It actualy works. just need to tweak some of the code. I have logging system in main.py logging.basicConfig(
level = logging.DEBUG,
format="%(asctime)s %(levelname)s %(name)s : %(message)s",
handlers = [
logging.StreamHandler(sys.stdout)
]
)
log = logging.getLogger("main")
# this doesn't appear even when using verbose
log.info("test") |
never mind already works. need to define it inside app |
Yep, devtools will be loading the app from Personally, I use |
Working example of combining aiohttp with other asyncio operation project
|- project
|- app.py
|- __main__.py
|- __init__.py
|- service.py
|- container.py
|- worker.py
|- http
|- app.py
|- action.py
|- asset
|- *.js
|- *.css
|- view
|- *.j2 http.app.py from aiohttp import web
app = web.Application()
# any aiohttp setup here, e.g routes middleware etc worker.py from app import app
async def httpserver():
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, host, port)
await site.start()
async def other_long_task():
while True:
await long_task()
await asyncio.sleep(1) __main__.py from worker import httpserver, other_long_task
if __name__ == "__main__":
loop = asyncio.get_event_loop()
asyncio.ensure_future(httpserver())
asyncio.ensure_future(other_long_task())
loop.run_forever() app.py from http.app import app
from worker import other_long_task
def app():
asyncio.ensure_future(other_long_task())
return app |
That's still less robust than the approach I described. We also generally discourage using globals like that (if you look at the demos/tutorials for aiohttp, the app object is always local to a function, never a global). My suggestion would look roughly more like:
With run_other_task() being defined something like:
Your current implementation will be more brittle as the lifetime of the other task is not being controlled by the app. Using a cleanup_ctx like this ensures that the task is created and torn down along with the app. As mentioned before, the app should be handling the overall running of the program (using |
I separate it because I also have a case when aiohttp is optional ( disabled web interface ) e.g we sometime use --web option to enable webgui So the web is not actually the first citizen here, the console app is. Each service will have their own start and shutdown mechanism. It feels more modular this way. I actually extract the code from web.run_app(app) and put it in separate code. Its give more flexibility for this scenario class Service:
services = []
def start(self) -> None:
loop = asyncio.get_event_loop()
try:
for d in services:
d.start()
loop.run_forever()
except asyncio.CancelledError:
logger.info("Receive Cancelled")
except KeyboardInterrupt:
logger.info("Receive Keyboard Interrupt")
except:
logger.info(sys.exc_info())
loop.run_until_complete(asyncio.wait([d.shutdown() for d in self._services]))
loop.close() |
I think as mentioned above, the solution to the original issue is to use `--root'. Please reopen if that is not the case. |
I haven't try --root options, currently it works using the approach you mention using separate file |
I think there are 2 slightly different cases. The case for root/ devtools runs main_app, and my local code spawns auxiliary_app in another process (they would be separate servers in production). By default, devtools would only watch for changes in main_app/, so in this case |
aiohttp-devtools version:
0.10.3
aiohttp version:
3.4.4
python version:
3.6
Platform:
Solus Linux
Issue Summary
I am using DDD structure for current project with separate application and webapi entry point. devtools doesnot use root path as project folder rather uses app_path which in this case unable watch changes on files inside application directory.
Steps to reproduce
Run dev server
$ export AIO_APP_PATH=webapi/
$ adev runserver
Make any changes on files inside webapi/, works as expected
Make any changes on files inside application/, doesn't work
Edit: Currently i am using runserver by directly editing
runserver/config.py
The text was updated successfully, but these errors were encountered: