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
81 stars 8 forks source link

asyncio event loop error #45

Open NikosAlexandris opened 1 week ago

NikosAlexandris commented 1 week ago

I have a fairly large documentation based on Material for MkDocs (and mkdocs version 1.6.1). I have followed the typical installation and (simplest) configuration instructions as per https://adrienbrignon.github.io/mkdocs-exporter/getting-started/#examples.

I try to serve the documentation, for example via

mkdocs serve --dirty --watch-theme --verbose

yet I get the following error

DEBUG   -  Running `post_build` event from plugin 'exporter-pdf'
Traceback (most recent call last):
  File "/something/something-prototype/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 272, in serve_command
    serve.serve(**kwargs)
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 85, in serve
    builder(config)
  File "/something/something-prototype/.venv/lib/python3.11/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 "/something/something-prototype/.venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 347, in build
    config.plugins.on_post_build(config=config)
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/mkdocs/plugins.py", line 602, in on_post_build
    return self.run_event('post_build', config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/site-packages/mkdocs/plugins.py", line 568, in run_event
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/something/something-prototype/.venv/lib/python3.11/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/lib/python3.11/asyncio/base_events.py", line 633, in run_until_complete
    future = tasks.ensure_future(future, loop=self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 659, in ensure_future
    return _ensure_future(coro_or_future, loop=loop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 665, in _ensure_future
    raise ValueError('The future belongs to a different loop than '
ValueError: The future belongs to a different loop than the one specified as the loop argument

Else, I got to understand that it is likely required to install playwright with various dependencies for different browsers, etc. I am unsure, however, if this indeed the problem. Since I don't use an apt based package manager, the attempt to

❯ playwright install --with-deps
BEWARE: your OS is not officially supported by Playwright; installing dependencies for ubuntu20.04-x64 as a fallback.
Installing dependencies...
Switching to root user to install dependencies...
[sudo] password for nik:
sh: line 1: apt-get: command not found
Failed to install browsers
Error: Installation process exited with code: 127

Isn't it unusual to exclusively support APT only ?

fails (too).

nbanyan commented 1 week ago

I get a similar error although mine is "attached to a different loop" rather than "belongs to a different loop". In my case setting concurrency to 1 avoids the issue at the cost of much higher compile time.

exporter:
  formats:
    pdf:
      concurrency: 1