Skip to content

Instantly share code, notes, and snippets.

@michaelfeil
Last active December 18, 2024 16:36
Show Gist options
  • Save michaelfeil/374585299208f4fb77220e5e3438d893 to your computer and use it in GitHub Desktop.
Save michaelfeil/374585299208f4fb77220e5e3438d893 to your computer and use it in GitHub Desktop.
python-delayed-import
from functools import cache
from typing import TYPE_CHECKING, Optional
@cache
def delayed_import_once():
global queue
import queue
if TYPE_CHECKING:
import queue
def needs_queue(maybe_queue: "Optional[queue.Queue]" = None) -> "queue.Queue":
delayed_import_once()
return queue.Queue(4) if not maybe_queue else maybe_queue
needs_queue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment