Skip to content

__del__ is not a valid async context #44

Open
@touilleMan

Description

@touilleMan

With triopg, I sometime encounter this kind of errors:

Exception ignored in: <bound method Connection.__del__ of <asyncpg.connection.Connection object at 0x7f908d309480>>
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/asyncpg/connection.py", line 124, in __del__
    self.terminate()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/asyncpg/connection.py", line 1059, in terminate
    self._abort()
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/asyncpg/connection.py", line 1086, in _abort
    self._protocol.abort()
  File "asyncpg/protocol/protocol.pyx", line 546, in asyncpg.protocol.protocol.BaseProtocol.abort
  File "/opt/python/3.6.3/lib/python3.6/asyncio/selector_events.py", line 603, in abort
    self._force_close(None)
  File "/opt/python/3.6.3/lib/python3.6/asyncio/selector_events.py", line 658, in _force_close
    self._loop.call_soon(self._call_connection_lost, exc)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/trio_asyncio/base.py", line 399, in call_soon
    return self._queue_handle(Handle(callback, args, self, context=context, is_sync=True))
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/trio_asyncio/async_.py", line 19, in _queue_handle
    self._q.put_nowait(handle)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/trio/_core/_ki.py", line 162, in wrapper
    return fn(*args, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/trio/_sync.py", line 906, in put_nowait
    _core.reschedule(task, outcome.Value(obj))
  File "<string>", line 7, in wrapper
RuntimeError: must be called from async context

Basically asyncpg's Connection object has a __del__ that wants to do an asyncio operation (so translated by trio-asyncio into doing a trio) but the weird place __del__ execute from doesn't seems to have a trio context :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions