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

UnboundLocalError: local variable 'ret' referenced before assignment #85

Closed
larryclean opened this issue Mar 21, 2017 · 4 comments
Closed
Labels

Comments

@larryclean
Copy link

i want to write logics at the "disconnect".but i got this error "local variable 'ret' referenced before assignment"

@sio.on('disconnect') async def disconnect(sid): # await user.logout(sid) await sio.sleep(2) print("disconnect" + sid)

@miguelgrinberg
Copy link
Owner

Can you paste the complete stack trace of the error please?

@larryclean
Copy link
Author

larryclean commented Mar 22, 2017

ERROR:aiohttp.server:Error handling request
Traceback (most recent call last):
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/socketio/asyncio_server.py", line 314, in _trigger_event
    ret = await self.handlers[namespace][event](*args)
  File "/Volumes/macsource/01-Project/02-Python/yikeweiqi/rtgame/views/realtime.py", line 71, in disconnect
    await sio.sleep(2)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/socketio/asyncio_server.py", line 222, in sleep
    return await self.eio.sleep(seconds)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_server.py", line 202, in sleep
    return await asyncio.sleep(seconds)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 524, in sleep
    return (yield from future)
  File "uvloop/future.pyx", line 230, in __iter__ (uvloop/loop.c:110600)
  File "uvloop/future.pyx", line 432, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:113980)
  File "uvloop/future.pyx", line 96, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:108829)
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/aiohttp/web_server.py", line 62, in handle_request
    resp = yield from self._handler(request)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 270, in _handle
    resp = yield from handler(request)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_server.py", line 135, in handle_request
    packets = await socket.handle_get_request(environ)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 72, in handle_get_request
    return await getattr(self, '_upgrade_' + transport)(environ)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 113, in _upgrade_websocket
    return await ws(environ)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/async_aiohttp.py", line 95, in __call__
    await self.handler(self)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 185, in _websocket_handler
    await self.close(wait=True, abort=True)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_socket.py", line 95, in close
    await self.server._trigger_event('disconnect', self.sid)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/engineio/asyncio_server.py", line 237, in _trigger_event
    ret = await self.handlers[event](*args)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/socketio/asyncio_server.py", line 366, in _handle_eio_disconnect
    await self._handle_disconnect(sid, '/')
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/socketio/asyncio_server.py", line 273, in _handle_disconnect
    await self._trigger_event('disconnect', '/', sid)
  File "/Volumes/macsource/01-Project/03-Pyvirtual/aiohttp/lib/python3.5/site-packages/socketio/asyncio_server.py", line 319, in _trigger_event
    return ret
UnboundLocalError: local variable 'ret' referenced before assignment

@miguelgrinberg
Copy link
Owner

Oh, wow, that is my bug. I'll have a fix up in a bit. Thanks!

@larryclean
Copy link
Author

No need to thank, you are too polite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants