Skip to content

Instantly share code, notes, and snippets.

View telemmaite's full-sized avatar

Dimitar Danev telemmaite

  • Bulgaria, Sofia
View GitHub Profile
@nkhitrov
nkhitrov / logger.py
Last active September 19, 2024 23:55
Configure uvicorn logs with loguru for FastAPI
"""
WARNING: dont use loguru, use structlog
https://gist.github.com/nkhitrov/38adbb314f0d35371eba4ffb8f27078f
Configure handlers and formats for application loggers.
"""
import logging
import sys
from pprint import pformat
@yeraydiazdiaz
yeraydiazdiaz / threadpool_future_cancellation.py
Last active February 6, 2021 04:59
Cancellation on run_in_executor using ThreadPoolExecutor
"""
A demonstration on how raising KeyboardInterrupt in the context of tasks
spawned via asyncio's loop.run_in_executor does not cancel the threads
using any of the cancellation methods in asyncio Futures.
The only "proper" way to cancel is to:
1. unregister the `atexit` registered `_python_exit` function
2. call `shutdown(wait=False)`
The reason is that the `thread` module registers `_python_exit` forcing a