chrysn / aiocoap

The Python CoAP library
Other
262 stars 119 forks source link

How to setup a debug mode on CoAP Server or an Hot Reloading on code changing? #356

Open J0hn3ch opened 1 week ago

J0hn3ch commented 1 week ago

Hi,

I have a simple question for my project with aiocoap. I running the server inside a container (Ubuntu 20.04 as base image). I have binding the server.py file to the container /app folder, and what I want is to setup a Debug mode or some configuration that allow to Live Reload (or Hot Reload) and restart with the new code the CoAP server.

Is there any parameter to setup? In aiocoap or in asyncio library?

Thanks you!

chrysn commented 1 week ago

There is no hot-reloading implemented in aiocoap (or in Python in general that I know of). I usually just stop and restart the server process, there's no notable delay in that, and a CoAP server is largely stateless anyway, and it avoids any of the lingering state issues hot reloading can have.

If you have any third party hot reload tool you are using in your application, you can probably hook aiocoap in with that, but that'll depend on that tool. At any rate, your choices are there to have the aiocoap server running outside (maybe passing requests in, or maybe switching the .site of the handler on reload) or to reload it along with the rest of the code (in which case I recommend you await .shutdown() to ensure that sockets can be reused) -- which of those two you choose depends on what you are changing, and what you expect to work across reloads.