Close motor AgnosticClient properly

Hi,

I am using motor AgnosticClient to manipulate MongoDB asynchronously, I am using next piece of code to close the client when my application is going to shutdown down.

io_loop = asyncio.get_event_loop()
my_close_task = io_loop.create_task(self.mongo_async_client.close())
io_loop.run_until_complete(my_close_task)

However, I got this error each time we close:

AttributeError: 'NoneType' object has no attribute 'send'

Complete trace:

self = <_UnixSelectorEventLoop running=False closed=False debug=False>
future = <[AssertionError() raised in repr()] Task object at 0x7fcb3ad890d0>

    def run_until_complete(self, future):
        """Run until the Future is done.
    
        If the argument is a coroutine, it is wrapped in a Task.
    
        WARNING: It would be disastrous to call run_until_complete()
        with the same coroutine twice -- it would wrap it in two
        different Tasks and that can't be good.
    
        Return the Future's result, or raise its exception.
        """
        self._check_closed()
    
        new_task = not futures.isfuture(future)
        future = tasks.ensure_future(future, loop=self)
        if new_task:
            # An exception is raised if the future didn't complete, so there
            # is no need to log the "destroy pending task" message
            future._log_destroy_pending = False
    
        future.add_done_callback(_run_until_complete_cb)
        try:
            self.run_forever()
        except:
            if new_task and future.done() and not future.cancelled():
                # The coroutine raised a BaseException. Consume the exception
                # to not log a warning, the caller doesn't have access to the
                # local task.
                future.exception()
            raise
        finally:
            future.remove_done_callback(_run_until_complete_cb)
        if not future.done():
            raise RuntimeError('Event loop stopped before Future completed.')
    
>       return future.result()
E       AttributeError: 'NoneType' object has no attribute 'send'

I’ve investigated over this forum and various resources but got no clues, could anyone help ?

Best