pygeoapi serve runs pygeoapi web application twice
Description
The pygeoapi serve command invokes the web application twice, as can be seen here:
https://github.com/geopython/pygeoapi/blob/e1fe05c1c16e40ab8bf6d07540e86d6f78b14172/pygeoapi/init.py#L99-L100
According to the click docs, context.forward() and context.invoke() are somewhat similar:
A mentioned in the docs, both ctx.forward() and ctx.invoke() result in the underlying function being called, which in pygeoapi's case means the call to serve_flask will run twice.
This can be seen if you run the pygeoapi server with pygeoapi serve and then try to stop it by pressing <CTRL+C> - You will need to press this key combination twice, as the first time it stops the first invocation (i.e. the call to ctx.forward() and proceeds to run pygeoapi server again, as it reaches the second invocation (i.e. the call to ctx.invoke()).
export PYGEOAPI_CONFIG=my-config.yml
export PYGEOAPI_OPENAPI=my-openapi.yml
pygeoapi serve
# in order to exit you need to press CTRL+C twice
@ricardogsilva Yes, this is a really annoying, because if we want to attach a debugger to the pygeoapi process, we are never sure which one to choose. It is also draining resources. Do you have any suggestions on how to fix this?
@doublebyte1
The fix would simply be to remove one of the calls, either ctx.forward() or ctx.invoke() - I haven't reviewed it in depth to see which one should be preferred.
However, I believe this would not be the reason for troubles when attaching a debugger, as each pygeoapi invocation is done in sequence, meaning the second one only starts running when one decides to press CTRL+C, which ends the first one and then starts the second
@ricardogsilva got it, then it's a different problem.