cnumr / ecoindex_python_fullstack

Refactoring of ecoindex in one monorepo using polylith pattern
Other
13 stars 3 forks source link

[Bug]: Python throw an error when submitting an analysis #98

Closed jeanremy closed 1 week ago

jeanremy commented 1 month ago

What happened?

When using the last image 2.28.0 on a Mac M1 (MacOS v14.5), an error shows up right after launching an analysis.

I'm on a fresh new install of Docker, and I've tried with version 2.27.1, which works fine.

The message is asyncio.run() cannot be called from a running event loop

Thank you!

Project

Ecoindex CLI

What OS do you use?

Mac

urls

No response

Relevant log output

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.12/site-packages/ecoindex/cli/app.py:228 in analyze                       │
│                                                                                                  │
│   225 │   │   count_errors = 0                                                                   │
│   226 │   │   task = progress.add_task("Processing", total=len(urls) * len(window_sizes))        │
│   227 │   │                                                                                      │
│ ❱ 228 │   │   analysis_results = run(                                                            │
│   229 │   │   │   bulk_analysis(                                                                 │
│   230 │   │   │   │   max_workers=max_workers,                                                   │
│   231 │   │   │   │   urls=urls,                                                                 │
│                                                                                                  │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮                     │
│ │         count_errors = 0                                                 │                     │
│ │        export_format = <ExportFormat.csv: 'csv'>                         │                     │
│ │          file_prefix = 'www.ecoindex.fr'                                 │                     │
│ │          html_report = True                                              │                     │
│ │ html_report_language = <Language.en: 'en'>                               │                     │
│ │           input_file = '/tmp/ecoindex-cli/input/www.ecoindex.fr.csv'     │                     │
│ │          logger_file = '/tmp/ecoindex-cli/logs/www.ecoindex.fr.log'      │                     │
│ │          max_workers = 8                                                 │                     │
│ │       no_interaction = False                                             │                     │
│ │          output_file = None                                              │                     │
│ │             progress = <rich.progress.Progress object at 0xffff643b1100> │                     │
│ │            recursive = False                                             │                     │
│ │              results = []                                                │                     │
│ │              sitemap = None                                              │                     │
│ │                 task = 0                                                 │                     │
│ │           tmp_folder = '/tmp/ecoindex-cli'                               │                     │
│ │                  url = ['https://www.ecoindex.fr']                       │                     │
│ │                 urls = {Url('https://www.ecoindex.fr/')}                 │                     │
│ │            urls_file = None                                              │                     │
│ │    wait_after_scroll = 3                                                 │                     │
│ │   wait_before_scroll = 3                                                 │                     │
│ │          window_size = ['1920,1080']                                     │                     │
│ │         window_sizes = [WindowSize(height=1080, width=1920)]             │                     │
│ ╰──────────────────────────────────────────────────────────────────────────╯                     │
│                                                                                                  │
│ /usr/local/lib/python3.12/asyncio/runners.py:194 in run                                          │
│                                                                                                  │
│   191 │   │   │   "asyncio.run() cannot be called from a running event loop")                    │
│   192 │                                                                                          │
│   193 │   with Runner(debug=debug, loop_factory=loop_factory) as runner:                         │
│ ❱ 194 │   │   return runner.run(main)                                                            │
│   195                                                                                            │
│   196                                                                                            │
│   197 def _cancel_all_tasks(loop):                                                               │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │        debug = None                                                     │                      │
│ │ loop_factory = None                                                     │                      │
│ │         main = <async_generator object bulk_analysis at 0xffff5f292820> │                      │
│ │       runner = <asyncio.runners.Runner object at 0xffff5f22ef60>        │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ /usr/local/lib/python3.12/asyncio/runners.py:89 in run                                           │
│                                                                                                  │
│    86 │   def run(self, coro, *, context=None):                                                  │
│    87 │   │   """Run a coroutine inside the embedded event loop."""                              │
│    88 │   │   if not coroutines.iscoroutine(coro):                                               │
│ ❱  89 │   │   │   raise ValueError("a coroutine was expected, got {!r}".format(coro))            │
│    90 │   │                                                                                      │
│    91 │   │   if events._get_running_loop() is not None:                                         │
│    92 │   │   │   # fail fast with short traceback                                               │
│                                                                                                  │
│ ╭────────────────────────────── locals ──────────────────────────────╮                           │
│ │ context = None                                                     │                           │
│ │    coro = <async_generator object bulk_analysis at 0xffff5f292820> │                           │
│ │    self = <asyncio.runners.Runner object at 0xffff5f22ef60>        │                           │
│ ╰────────────────────────────────────────────────────────────────────╯                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: a coroutine was expected, got <async_generator object bulk_analysis at 0xffff5f292820>

Code of Conduct

vvatelot commented 1 month ago

Hello @jeanremy, thanks for your issue. Can you provide me the exact command that you use to get this error ?

Thanks!

jeanremy commented 1 month ago

Of course, this happens when lauching the analyze command. For example ecoindex-cli analyze --url https://www.google.fr --html-report. Please let me know if I can be more helpful. Thanks !

remi commented 4 weeks ago

Same for me:

Input

$ alias ecoindex-cli="docker run -it --rm -v /tmp/ecoindex-cli:/tmp/ecoindex-cli vvatelot/ecoindex-cli:latest ecoindex-cli"
$ ecoindex-cli analyze --url https://google.fr

Output

📁️ Urls recorded in file `/tmp/ecoindex-cli/input/google.fr.csv`
There are 1 url(s), do you want to process? [Y/n]: y
1 urls for 1 window size with 2 maximum workers
  0% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0/1 • 0:00:00 • -:--:--
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /usr/local/lib/python3.12/site-packages/ecoindex/cli/app.py:228 in analyze                       │
│                                                                                                  │
│   225 │   │   count_errors = 0                                                                   │
│   226 │   │   task = progress.add_task("Processing", total=len(urls) * len(window_sizes))        │
│   227 │   │                                                                                      │
│ ❱ 228 │   │   analysis_results = run(                                                            │
│   229 │   │   │   bulk_analysis(                                                                 │
│   230 │   │   │   │   max_workers=max_workers,                                                   │
│   231 │   │   │   │   urls=urls,                                                                 │
│                                                                                                  │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮                     │
│ │         count_errors = 0                                                 │                     │
│ │        export_format = <ExportFormat.csv: 'csv'>                         │                     │
│ │          file_prefix = 'google.fr'                                       │                     │
│ │          html_report = False                                             │                     │
│ │ html_report_language = <Language.en: 'en'>                               │                     │
│ │           input_file = '/tmp/ecoindex-cli/input/google.fr.csv'           │                     │
│ │          logger_file = '/tmp/ecoindex-cli/logs/google.fr.log'            │                     │
│ │          max_workers = 2                                                 │                     │
│ │       no_interaction = False                                             │                     │
│ │          output_file = None                                              │                     │
│ │             progress = <rich.progress.Progress object at 0xed2c5f61b500> │                     │
│ │            recursive = False                                             │                     │
│ │              results = []                                                │                     │
│ │              sitemap = None                                              │                     │
│ │                 task = 0                                                 │                     │
│ │           tmp_folder = '/tmp/ecoindex-cli'                               │                     │
│ │                  url = ['https://google.fr']                             │                     │
│ │                 urls = {Url('https://google.fr/')}                       │                     │
│ │            urls_file = None                                              │                     │
│ │    wait_after_scroll = 3                                                 │                     │
│ │   wait_before_scroll = 3                                                 │                     │
│ │          window_size = ['1920,1080']                                     │                     │
│ │         window_sizes = [WindowSize(height=1080, width=1920)]             │                     │
│ ╰──────────────────────────────────────────────────────────────────────────╯                     │
│                                                                                                  │
│ /usr/local/lib/python3.12/asyncio/runners.py:194 in run                                          │
│                                                                                                  │
│   191 │   │   │   "asyncio.run() cannot be called from a running event loop")                    │
│   192 │                                                                                          │
│   193 │   with Runner(debug=debug, loop_factory=loop_factory) as runner:                         │
│ ❱ 194 │   │   return runner.run(main)                                                            │
│   195                                                                                            │
│   196                                                                                            │
│   197 def _cancel_all_tasks(loop):                                                               │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │        debug = None                                                     │                      │
│ │ loop_factory = None                                                     │                      │
│ │         main = <async_generator object bulk_analysis at 0xed2c5f67e820> │                      │
│ │       runner = <asyncio.runners.Runner object at 0xed2c65de1c70>        │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ /usr/local/lib/python3.12/asyncio/runners.py:89 in run                                           │
│                                                                                                  │
│    86 │   def run(self, coro, *, context=None):                                                  │
│    87 │   │   """Run a coroutine inside the embedded event loop."""                              │
│    88 │   │   if not coroutines.iscoroutine(coro):                                               │
│ ❱  89 │   │   │   raise ValueError("a coroutine was expected, got {!r}".format(coro))            │
│    90 │   │                                                                                      │
│    91 │   │   if events._get_running_loop() is not None:                                         │
│    92 │   │   │   # fail fast with short traceback                                               │
│                                                                                                  │
│ ╭────────────────────────────── locals ──────────────────────────────╮                           │
│ │ context = None                                                     │                           │
│ │    coro = <async_generator object bulk_analysis at 0xed2c5f67e820> │                           │
│ │    self = <asyncio.runners.Runner object at 0xed2c65de1c70>        │                           │
│ ╰────────────────────────────────────────────────────────────────────╯                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: a coroutine was expected, got <async_generator object bulk_analysis at 0xed2c5f67e820>
vvatelot commented 3 weeks ago

Hello, I confirm that there is a bug on the latest version 2.28.0 I try to fix it as soon as I can.

In the same time, you can use the last 2.27.1 version as explained by @jeanremy