adrienbrignon / mkdocs-exporter

⚡ The fastest and most configurable plugin for MkDocs, allowing seamless export of individual pages and/or entire documentation as PDF documents.
https://adrienbrignon.github.io/mkdocs-exporter/
MIT License
83 stars 9 forks source link

asyncio lock `Future attached to a different loop` #49

Open nbanyan opened 2 weeks ago

nbanyan commented 2 weeks ago

When I have formats.pdf.concurrency set higher than 2 and the site includes more than a few pages I get the following error:

Traceback (most recent call last):
  File "/Users/training4/venv3.9/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/__main__.py", line 268, in serve_command
    serve.serve(**kwargs)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 85, in serve
    builder(config)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/commands/build.py", line 347, in build
    config.plugins.on_post_build(config=config)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/plugins.py", line 602, in on_post_build
    return self.run_event('post_build', config=config)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs/plugins.py", line 568, in run_event
    result = method(**kwargs)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/formats/pdf/plugin.py", line 154, in _on_post_build_1
    self.loop.run_until_complete(asyncio.gather(*concurrently(self.tasks, max(1, self.config.concurrency or 1))))
  File "/usr/local/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/helpers.py", line 29, in limit
    return await asyncio.create_task(coroutine)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/formats/pdf/plugin.py", line 135, in render
    pdf, pages = await self.renderer.render(html)
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/formats/pdf/renderer.py", line 87, in render
    await self.browser.launch()
  File "/Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/formats/pdf/browser.py", line 57, in launch
    async with self.lock:
  File "/usr/local/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/locks.py", line 14, in __aenter__
    await self.acquire()
  File "/usr/local/Cellar/python@3.9/3.9.20/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/locks.py", line 120, in acquire
    await fut
RuntimeError: Task <Task pending name='Task-5' coro=<Plugin.on_post_page.<locals>.render() running at /Users/training4/venv3.9/lib/python3.9/site-packages/mkdocs_exporter/formats/pdf/plugin.py:135> cb=[<TaskWakeupMethWrapper object at 0x10efeae20>()]> got Future <Future pending> attached to a different loop