Skip to content
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

Stop server error #2637

Closed
johnroper100 opened this issue Dec 31, 2017 · 8 comments
Closed

Stop server error #2637

johnroper100 opened this issue Dec 31, 2017 · 8 comments
Labels

Comments

@johnroper100
Copy link

Long story short

I'm trying to send a message to the server that stops both the web server as well as the python-socketio server (they are connected).

I currently have this code:

import socketio
from aiohttp import web

sio = socketio.AsyncServer(async_mode='aiohttp')
app = web.Application()
sio.attach(app)

web.run_app(app)

@sio.on('quit tonalite', namespace='/tonalite')
async def quit_tonalite(sid, message):
    sys.exit(0)

Expected behaviour

I would expect the script to close just as if I was clicking CTRL+C in the terminal.

Actual behaviour

I get this error:

message async handler error
Traceback (most recent call last):
  File "/home/johnroper100/.local/lib/python3.6/site-packages/engineio/asyncio_server.py", line 266, in _trigger_event
    ret = await self.handlers[event](*args)
  File "/home/johnroper100/.local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 364, in _handle_eio_message
    await self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)
  File "/home/johnroper100/.local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 294, in _handle_event
    await self._handle_event_internal(self, sid, data, namespace, id)
  File "/home/johnroper100/.local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 297, in _handle_event_internal
    r = await server._trigger_event(data[0], namespace, sid, *data[1:])
  File "/home/johnroper100/.local/lib/python3.6/site-packages/socketio/asyncio_server.py", line 325, in _trigger_event
    ret = await self.handlers[namespace][event](*args)
  File "tonalite.py", line 373, in quit_tonalite
    sys.exit(0)
SystemExit: 0

Your environment

I'm using aiohttp as a server on both Windows and Linux.

@asvetlov
Copy link
Member

If you want emulate Ctrl+C -- send KeyboardInterrupt signal, not SystemExit.

P.S. Stopping web server by regular websocket message sounds very strange for me. The server is multi-client application by definition, stopping serving all connections by single request from arbitrary client sounds weird.

@hellysmile
Copy link
Member

Try to send signal.SIGINT to own process os.getpid()

@johnroper100
Copy link
Author

Basically, this is running without a console with only a html gui so I need the message to shutdown down the application.

@asvetlov
Copy link
Member

How do you shutdown, e.g. NGINX?
Or your box at all?
Is it possible from html gui?
Perhaps no.
Why do you need shutdown particular websocket server?

@johnroper100
Copy link
Author

I have this in a single python script that receives messages from a html+js client. I use pyinstaller on this script, but there is no console when using pyinstaller. This solution is supposed to be the same as closing the program by closing the console if there were one.

@johnroper100
Copy link
Author

It's all in a repo here: https://github.com/johnroper100/Tonalite

@asvetlov
Copy link
Member

asvetlov commented Jan 2, 2018

@hellysmile approach should work

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants