This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lilydjwg
Recipients asvetlov, lilydjwg, yselivanov
Date 2020-12-19.08:09:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
import asyncio

async def crash(key):
  raise Exception('crash!')

async def wait(fu):
  await fu

async def main():
  crasher = asyncio.create_task(crash(()))
  fs = [wait(crasher) for _ in range(10)]
  for fu in asyncio.as_completed(fs):
      await fu
    except Exception:
      import traceback

if __name__ == '__main__':

This code will give a very long traceback 10 times. I expect it to be short.

I'm caching the result of an async function like this:

  async def get(
    key: Hashable,
    func: Callable[[Hashable], Coroutine[Any, Any, Any]],
  ) -> Any:
    async with self.lock:
      cached = self.cache.get(key)
      if cached is None:
        coro = func(key)
        fu = asyncio.create_task(coro)
        self.cache[key] = fu

    if asyncio.isfuture(cached): # pending
      return await cached # type: ignore
    elif cached is not None: # cached
      return cached
    else: # not cached
      r = await fu
      self.cache[key] = r
      return r

It works fine, except that when there is an exception the traceback is very long.
Date User Action Args
2020-12-19 08:09:24lilydjwgsetrecipients: + lilydjwg, asvetlov, yselivanov
2020-12-19 08:09:24lilydjwgsetmessageid: <>
2020-12-19 08:09:24lilydjwglinkissue42682 messages
2020-12-19 08:09:24lilydjwgcreate