diff options
| author | 2020-12-14 05:49:58 +0100 | |
|---|---|---|
| committer | 2021-01-09 20:10:54 +0100 | |
| commit | 73d7d748a550e644980d2604542d279472eb1b0c (patch) | |
| tree | 4f1e12aeddd586b23c8fe8c768cda784f56cda8a | |
| parent | Simplify the implementation of the custom strainer (diff) | |
Run html parsing in an executor
The parsing may take up to a few hundred ms depending on the amount
of work it has to do
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/info/doc/_cog.py | 6 | 
1 files changed, 5 insertions, 1 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 07a287572..093e5cdb7 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -6,6 +6,7 @@ import re  import sys  from collections import defaultdict  from contextlib import suppress +from functools import partial  from types import SimpleNamespace  from typing import Dict, List, NamedTuple, Optional, Union @@ -126,7 +127,10 @@ class CachedParser:              while self._queue:                  item, soup = self._queue.pop()                  try: -                    markdown = get_symbol_markdown(soup, item) +                    markdown = await bot_instance.loop.run_in_executor( +                        None, +                        partial(get_symbol_markdown, soup, item), +                    )                      await doc_cache.set(item, markdown)                  except Exception:                      log.exception(f"Unexpected error when handling {item}")  |