Sanic process lingering when debug stopped in VS Code

When using sanic with workers in VS Code, even with debug=True, some workers appear to be left running after I stop it debugging. Is that expected behaviour? I’m on windows 10 with python 3.6 and VS Code 1.28.2.

It may be related to the discussions Following: `auto_reload` support for Windows about hooking into the debuggers in various IDEs.

from sanic import Sanic
from sanic.response import json

app = Sanic()

@app.route('/')
async def test(request):
    return json({'hello': "world"})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8020, workers=10)

2018-10-28 16:05:52 -0000] - (sanic.access)[INFO][127.0.0.1:65343]: GET http://127.0.0.1:8020/ 200 24
Executing <Task finished coro=<Sanic.handle_request() done, defined at C:\Users\mark\AppData\Roaming\Python\Python36\site-packages\sanic\app.py:561> result=None created at C:\Users\mark\AppData\Roaming\Python\Python36\site-packages\sanic\server.py:295> took 5.000 seconds

I then stopped debugging so I get the command prompt, but requests are still handled and I have to restart VS Code to stop them:

C:\Users\mark\source\repos\sanic_threads>Executing <Handle BaseSelectorEventLoop._accept_connection(functools.par…e, debug=True), <socket.socke…0.0.0’, 8020)>, None, <Server socke…0.0’, 8020)>]>, 100) created at C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\selector_events.py:262> took 14.125 seconds
Executing <Handle BaseSelectorEventLoop._accept_connection(functools.par…e, debug=True), <socket.socke…0.0.0’, 8020)>, None, <Server socke…0.0’, 8020)>]>, 100) created at C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\asyncio\selector_events.py:262> took 14.125 seconds
[2018-10-28 16:06:06 -0000] - (sanic.access)[INFO][127.0.0.1:65346]: GET http://127.0.0.1:8020/ 200 24
Executing <Task finished coro=<Sanic.handle_request() done, defined at C:\Users\mark\AppData\Roaming\Python\Python36\site-packages\sanic\app.py:561> result=None created at C:\Users\mark\AppData\Roaming\Python\Python36\site-packages\sanic\server.py:295> took 5.000 seconds

Since you are not passing auto_reload=True in your app config, it’s unlikely to be that. It may be related to the fact that you’re running 10 workers. See if running with a single worker fixes it for now - obviously that’s probably not okay for your production target, but it may help you with your local development.

I really, really need to check out if Windows supports sharing a socket port between multiple process. AFAIK, this should not work on Windows - unless something has changed in the Windows kernel. Anyway, I have to finish setting up a Windows VM to make such tests.

@vltr I’m pretty sure the win10/server2012+ offer port sharing. But I could be wrong.

I think so too, but I want to test this to be completely sure :wink: