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

RuntimeError: There is no current event loop in thread 'MainThread'. #3

Closed
JayaramaKrishnaGudipati opened this issue May 24, 2023 · 13 comments

Comments

@JayaramaKrishnaGudipati

Hi,

I have recently switched from mkdocs-with-pdf plugin to your plugin, first I would like to thank you for the contribution.
The below error message is not allowing to proceed further,

File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/plugin.py", line 141, in on_post_build
loop = asyncio.get_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/events.py", line 677, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.

Could you please check on this one and kindly support to resolve the issue.

@JayaramaKrishnaGudipati
Copy link
Author

Hi @adrienbrignon,

I see this as some plugin issue, could you please verify once and confirm with your thoughts on this issue.

Thanks

@adrienbrignon adrienbrignon added the bug Something isn't working label May 27, 2023
@adrienbrignon
Copy link
Owner

Hello @JayaramaKrishnaGudipati,

Thank you for submitting an issue.

Could you please assist me in debugging this problem by sharing your mkdocs.yml configuration file and any other details you consider relevant?

Thanks

@JayaramaKrishnaGudipati
Copy link
Author

Thank you @adrienbrignon for responding on the issue.

I have an mkdocs.yml file with extensions and other plugins included in it.
There is a separate mkdocs-pdf.yml file which we are including for pdf generation and this file inherits mkdocs.yml file.
The only change I have done in this file is, I have replaced "with-pdf" plugin with "mkdocs exporter" plugin and used the given style sheets, buttons after that I see the given error message.

This is the mkdocs-pdf.yml file used for processing the pdf generation,

base configuration for the page

INHERIT: mkdocs.yml

plugins:
mkdocs/exporter:
mkdocs/exporter/pdf:
concurrency: 8
covers:
front: resources/templates/covers/front.html.j2
stylesheets:
- resources/stylesheets/pdf.scss
# - pdf-templates/styles.scss
mkdocs/exporter/extras:
buttons:
- title: Download as PDF
enabled: !!python/name:mkdocs_exporter.plugins.pdf.button.enabled
icon: !!python/name:mkdocs_exporter.plugins.pdf.button.icon
href: !!python/name:mkdocs_exporter.plugins.pdf.button.href
download: !!python/name:mkdocs_exporter.plugins.pdf.button.download

Please let me know if you need more details,

Thanks

@adrienbrignon
Copy link
Owner

adrienbrignon commented May 29, 2023

Thank you @JayaramaKrishnaGudipati for the details.

Unfortunately, I am not able to reproduce your issue.
Could you please provide me with some more details?

  • Parent mkdocs.yml configuration
  • The version of mkdocs installed

Also, by the way the button is defined in your configuration file; it makes me wonder if you're using the latest version of this plugin.
Could you try updating it to version 2.0.1 if you haven't already?

Thanks

@JayaramaKrishnaGudipati
Copy link
Author

JayaramaKrishnaGudipati commented May 30, 2023

Hi @adrienbrignon,

Thanks for contributing the new version, I have updated the version to 2.0.1 and tried, I see the same issue, Please find the below full details of mkdocs.yml and on the error message.

mkdocs version: 1.4.2

###########################################################################################
mkdocs.yml:

INHERIT: mkdocs-nav.yml

# --- site configuration ---
site_name: 'use-mkdocs'
site_url: !!python/object/apply:os.getenv ["SITE_URL"]
repo_name: !!python/object/apply:os.getenv ["CI_PROJECT_PATH"]
repo_url: !!python/object/apply:os.getenv ["CI_PROJECT_URL"]
edit_uri: edit/main/
# --- site configuration ---

docs_dir: .
use_directory_urls: false

theme:
  name: #company theme
  include_search_page: false
  search_index_only: true
  language: en
  palette:
   - scheme: default
     primary: teal
     accent: teal
  features:
   - page.toc
   - navigation.tabs 
   - navigation.tabs.sticky 
   - navigation.tertiary 
   - navigation.top 
   - navigation.expand 
extra:
  generator: false
  page_license_text: ' '
  version:
    provider: mike
    
markdown_extensions:
  abbr: {} 
  admonition: {}
  attr_list: {}
  codehilite:
    guess_lang: true
    linenums: true
  def_list: {}
  footnotes: {}
  markdown_include.include:
    base_path: docs
  markdown_katex: {}
  md_in_html: {} 
  meta: {}
  pymdownx.arithmatex:
    generic: true
  pymdownx.betterem:
    smart_enable: all
  pymdownx.caret: {}
  pymdownx.critic:
    mode: accept 
  pymdownx.details: {} 
  pymdownx.emoji:
    emoji_generator: !!python/name:pymdownx.emoji.to_svg
  pymdownx.highlight:
    linenums: true
    linenums_style: pymdownx-inline
  pymdownx.inlinehilite: {}
  pymdownx.keys: {} 
  pymdownx.magiclink: {}
  pymdownx.mark: {}
  pymdownx.smartsymbols: {}
  pymdownx.snippets: {}
  pymdownx.superfences:
    custom_fences:
      - name: mermaid
        class: mermaid
        format: !!python/name:pymdownx.superfences.fence_code_format
  pymdownx.tabbed: {}
  pymdownx.tasklist: {}
  pymdownx.tilde: {}
  toc:
    permalink: '#' 

plugins:
  search:
    indexing: 'full'
  macros: {}
  multirepo:
    cleanup: false
    temp_dir: .deps

#########################################################################################
Error Message:

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/__main__.py", line 2[50](https://code.siemens.com/reusable-ci/include/use-mkdocs/-/jobs/120865145#L50), in build_command
    build.build(cfg, dirty=not clean)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/build.py", line 332, in build
    config.plugins.run_event('post_build', config=config)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/plugin.py", line 141, in on_post_build
    loop = asyncio.get_event_loop()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/events.py", line [67](https://code.siemens.com/reusable-ci/include/use-mkdocs/-/jobs/120865145#L67)7, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.

###########################################################################################

mkdocs-pdf.yml:

INHERIT: mkdocs.yml

theme:
  name: 'material'

plugins:
  mkdocs/exporter:
  mkdocs/exporter/pdf:
    concurrency: 8
    covers:
      front: resources/templates/covers/front.html.j2
    stylesheets:
      - resources/stylesheets/pdf.scss
  mkdocs/exporter/extras:
    buttons:
      - title: Download as PDF
        enabled: !!python/name:mkdocs_exporter.plugins.pdf.button.enabled
        icon: !!python/name:mkdocs_exporter.plugins.pdf.button.icon
        href: !!python/name:mkdocs_exporter.plugins.pdf.button.href
        download: !!python/name:mkdocs_exporter.plugins.pdf.button.download

#########################################################################################

Note:

We are actually using a different theme designed by our company for mkdocs and initially when I used this new version (2.0.1) plugin it has given an error message that this theme was not supported, then I changed to "material" theme (which we are following for pdf generation) and I see the same asyncio error message.

Please suggest to fix this issue and proceed further.

Thanks

@adrienbrignon
Copy link
Owner

adrienbrignon commented May 30, 2023

Hello again @JayaramaKrishnaGudipati,

Thank you for the precious details you've provided.
I'll investigate further and get back to you with a solution.

At the moment, I'm thinking that it may be a compatibility issue with the multirepo plugin as it uses some asyncio features too.

In the meantime, could you please try to update to the v3.0.1 version?
This new serie of releases features an attempt to fix the issue you are currently experiencing (There is no current event loop in thread...) and support for custom themes, as long as they are based on a officially supported one (which are, at the time of writing: material and readthedocs).

For instance, if your custom theme is called company and is itself based on the material one, you could configure MkDocs like this:

theme:
  name: company

plugins:
  - mkdocs/exporter:
      theme: material 
  - mkdocs/exporter/pdf:
      concurrency: 8

Please note the theme key of the mkdocs/exporter plugin's configuration.

Finally, thank you for taking the time to contribute to this discussion; you're helping me making this plugin better and for that, I am truly grateful.

@adrienbrignon
Copy link
Owner

Hey @JayaramaKrishnaGudipati,

First of all, sorry for the notifications!
I've just released the 3.0.2 version that should resolve the compatibility issues between the multirepo plugin and this one.

Could you please upgrade and let me know if the issue is resolved?

Thanks

@JayaramaKrishnaGudipati
Copy link
Author

Hello @adrienbrignon

No Problem, its my pleasure to work with you on this issue. I'm happy to contribute to your plugin.
Thanks for your detailed instructions.

I have upgraded the version to 3.0.2 and I see the get_event_loop issue is resolved but I see some error on "playwright" as shown below, I have even upgraded the playwright version from 1.33.0 to 1.34.0

Traceback (most recent call last):
File "/usr/local/bin/mkdocs", line 8, in
sys.exit(cli())
^^^^^
File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/mkdocs/main.py", line 250, in build_command
build.build(cfg, dirty=not clean)
File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/build.py", line 332, in build
config.plugins.run_event('post_build', config=config)
File "/usr/local/lib/python3.11/site-packages/mkdocs/plugins.py", line 522, in run_event
result = method(**kwargs)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/plugin.py", line 152, in on_post_build
self.loop.run_until_complete(asyncio.gather(*concurrently(self.tasks, max(1, self.config.concurrency or 1))))
File "/usr/local/lib/python3.11/site-packages/nest_asyncio.py", line 90, in run_until_complete
return f.result()
^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/tasks.py", line 269, in __step
result = coro.throw(exc)
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/plugin.py", line 148, in limit
return await asyncio.create_task(coroutine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/futures.py", line 287, in await
yield self # This tells Task to wait for completion.
^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/tasks.py", line 339, in __wakeup
future.result()
File "/usr/local/lib/python3.11/asyncio/futures.py", line 203, in result
raise self._exception.with_traceback(self._exception_tb)
File "/usr/local/lib/python3.11/asyncio/tasks.py", line 267, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/plugin.py", line 122, in render
pdf = await self.renderer.render(page)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/plugins/pdf/renderer.py", line 53, in render
await self.browser.launch()
File "/usr/local/lib/python3.11/site-packages/mkdocs_exporter/browser.py", line 50, in launch
self.browser = await self.playwright.chromium.launch(headless=True, args=self.args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 14655, in launch
await self._impl_obj.launch(
File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 95, in launch
Browser, from_channel(await self._channel.send("launch", params))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 61, in send
return await self._connection.wrap_api_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call
return await cb()
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
result = next(iter(done)).result()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/futures.py", line 203, in result
raise self._exception.with_traceback(self._exception_tb)
playwright._impl._api_types.Error: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1064/chrome-linux/chrome
╔════════════════════════════════════════════════════════════╗
║ Looks like Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ playwright install ║
║ ║
║ <3 Playwright Team ║
╚════════════════════════════════════════════════════════════╝

Please let me know how to resolve this above error and proceed further.

Note:

The mkdocs file is working and proceeding further till the playwright issue as describe above if the theme was declared like this,

INHERIT: mkdocs.yml

theme:
name: 'material'

plugins:
mkdocs/exporter:
mkdocs/exporter/pdf:
concurrency: 8
covers:
front: resources/templates/covers/front.html.j2
stylesheets:
- resources/stylesheets/pdf.scss
mkdocs/exporter/extras:
buttons:
- title: Download as PDF
enabled: !!python/name:mkdocs_exporter.plugins.pdf.button.enabled
icon: !!python/name:mkdocs_exporter.plugins.pdf.button.icon
href: !!python/name:mkdocs_exporter.plugins.pdf.button.href
download: !!python/name:mkdocs_exporter.plugins.pdf.button.download

If it was given like the below one, I see the job is stopping with config error,

INHERIT: mkdocs.yml

plugins:
mkdocs/exporter:
theme:'material'
mkdocs/exporter/pdf:
concurrency: 8
covers:
front: resources/templates/covers/front.html.j2
stylesheets:
- resources/stylesheets/pdf.scss
mkdocs/exporter/extras:
buttons:
- title: Download as PDF
enabled: !!python/name:mkdocs_exporter.plugins.pdf.button.enabled
icon: !!python/name:mkdocs_exporter.plugins.pdf.button.icon
href: !!python/name:mkdocs_exporter.plugins.pdf.button.href
download: !!python/name:mkdocs_exporter.plugins.pdf.button.download

ERROR - Config value 'plugins': Invalid config options for the 'mkdocs/exporter' plugin.
Aborted with 1 Configuration Errors!

Thanks

@adrienbrignon
Copy link
Owner

Hey @JayaramaKrishnaGudipati,

Thank you, I'm glad to hear that the get_event_loop issues are resolved!

For your current issue, it seems that Playwright is not fully installed.
Could you please try running the following command:

playwright install --with-deps

What this command does basically, is:

  • Install dependencies required by browsers
  • Download web browsers
  • Install web browsers

Thanks

@JayaramaKrishnaGudipati
Copy link
Author

Hi @adrienbrignon,

I actually installed and upgraded the playwright python package with version 1.34.0.
The program I'm working on will be executed in a CI pipeline as a job from a GitLab runner with all the given package dependencies. I'm not sure where else this installation you have suggested need to be performed. Sorry for the continuous queries. :)

Please let me know where this installation need to be done.

Thanks.

@adrienbrignon
Copy link
Owner

adrienbrignon commented May 31, 2023

No problem.

Typically, you'll need to run this command after installing dependencies (via pip for instance).
Then, you should be able to generate PDF documents.

This project features a Dockerfile and a GitHub Workflow that do perform this procedure (some commands are defined in this Makefile), feel free to draw inspiration from them.

To sum things up:

  • Install your dependencies (with pip, poetry...)
  • Install Playwright dependencies (playwright install --with-deps)
  • Run MkDocs

@adrienbrignon adrienbrignon removed the bug Something isn't working label May 31, 2023
@JayaramaKrishnaGudipati
Copy link
Author

Hey @adrienbrignon ,

I tried updating the playwright installation in the docker image, I faced the below issue, looks like the image is distributing debain version of linux and here I see it supports only on Ubuntu.
Please share your thoughts if there is any other work around to proceed with this playwright.

Warning: The file chosen for install of fonttools 4.39.1 (fonttools-4.39.1-py3-none-any.whl) is yanked. Reason for being yanked: regression when building VF with STAT from DesignSpace v5:fonttools/fonttools#3045
++ arch

  • [[ x86_64 == \a\a\r\c\h\6\4 ]]
  • [[ ! -f /etc/os-release ]]
    ++ bash -c 'source /etc/os-release && echo $ID'
  • ID=debian
  • [[ debian != \u\b\u\n\t\u ]]
  • echo 'ERROR: cannot install on debian distribution - only Ubuntu is supported'
  • exit 1
    ERROR: cannot install on debian distribution - only Ubuntu is supported
    Failed to install browsers
    Error: Failed to install chrome
    error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1

Thanks

@adrienbrignon
Copy link
Owner

Hey @JayaramaKrishnaGudipati,

As a potential workaround, you could use a container based on Ubuntu to build your documentation.
For official Debian support by Playwright, I would head to their issue tracker.

I will now close this issue as it is resolved.

Again, thank you for your collaboration in fixing this issue, it is very much appreciated.

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

No branches or pull requests

2 participants