a_sync package
Subpackages
- a_sync.a_sync package
- Subpackages
- Submodules
- a_sync.a_sync._descriptor module
ASyncDescriptor
ASyncDescriptor.__init__()
ASyncDescriptor._all()
ASyncDescriptor._any()
ASyncDescriptor._asyncify()
ASyncDescriptor._max()
ASyncDescriptor._min()
ASyncDescriptor._sum()
ASyncDescriptor.map()
ASyncDescriptor._await
ASyncDescriptor.all
ASyncDescriptor.any
ASyncDescriptor.default
ASyncDescriptor.field_name
ASyncDescriptor.max
ASyncDescriptor.min
ASyncDescriptor.modifiers
ASyncDescriptor.sum
ASyncDescriptor.wrapped
- a_sync.a_sync._flags module
- a_sync.a_sync._helpers module
- a_sync.a_sync._kwargs module
- a_sync.a_sync._meta module
- a_sync.a_sync.abstract module
- a_sync.a_sync.base module
- a_sync.a_sync.config module
- a_sync.a_sync.decorator module
- a_sync.a_sync.flags module
- a_sync.a_sync.function module
ASyncDecorator
ASyncDecoratorAsyncDefault
ASyncDecoratorAsyncDefault.__call__()
ASyncDecoratorAsyncDefault.__init__()
ASyncDecoratorAsyncDefault._asyncify()
ASyncDecoratorAsyncDefault.validate_inputs()
ASyncDecoratorAsyncDefault._await
ASyncDecoratorAsyncDefault.default
ASyncDecoratorAsyncDefault.modifiers
ASyncDecoratorAsyncDefault.wrapped
ASyncDecoratorSyncDefault
ASyncFunction
ASyncFunction.__call__()
ASyncFunction.__init__()
ASyncFunction._asyncify()
ASyncFunction.all()
ASyncFunction.any()
ASyncFunction.map()
ASyncFunction.max()
ASyncFunction.min()
ASyncFunction.sum()
ASyncFunction._async_def
ASyncFunction._async_wrap
ASyncFunction._asyncified
ASyncFunction._await
ASyncFunction._modified_fn
ASyncFunction._sync_default
ASyncFunction._sync_wrap
ASyncFunction.default
ASyncFunction.fn
ASyncFunction.modifiers
ASyncFunction.wrapped
ASyncFunctionAsyncDefault
ASyncFunctionAsyncDefault.__call__()
ASyncFunctionAsyncDefault.__init__()
ASyncFunctionAsyncDefault._asyncify()
ASyncFunctionAsyncDefault.all()
ASyncFunctionAsyncDefault.any()
ASyncFunctionAsyncDefault.map()
ASyncFunctionAsyncDefault.max()
ASyncFunctionAsyncDefault.min()
ASyncFunctionAsyncDefault.sum()
ASyncFunctionAsyncDefault._async_def
ASyncFunctionAsyncDefault._async_wrap
ASyncFunctionAsyncDefault._asyncified
ASyncFunctionAsyncDefault._await
ASyncFunctionAsyncDefault._modified_fn
ASyncFunctionAsyncDefault._sync_default
ASyncFunctionAsyncDefault._sync_wrap
ASyncFunctionAsyncDefault.default
ASyncFunctionAsyncDefault.fn
ASyncFunctionAsyncDefault.modifiers
ASyncFunctionAsyncDefault.wrapped
ASyncFunctionSyncDefault
ASyncFunctionSyncDefault.__call__()
ASyncFunctionSyncDefault.__init__()
ASyncFunctionSyncDefault._asyncify()
ASyncFunctionSyncDefault.all()
ASyncFunctionSyncDefault.any()
ASyncFunctionSyncDefault.map()
ASyncFunctionSyncDefault.max()
ASyncFunctionSyncDefault.min()
ASyncFunctionSyncDefault.sum()
ASyncFunctionSyncDefault._async_def
ASyncFunctionSyncDefault._async_wrap
ASyncFunctionSyncDefault._asyncified
ASyncFunctionSyncDefault._await
ASyncFunctionSyncDefault._modified_fn
ASyncFunctionSyncDefault._sync_default
ASyncFunctionSyncDefault._sync_wrap
ASyncFunctionSyncDefault.default
ASyncFunctionSyncDefault.fn
ASyncFunctionSyncDefault.modifiers
ASyncFunctionSyncDefault.wrapped
_ModifiedMixin
_check_not_genfunc()
_validate_argspec()
_validate_wrapped_fn()
- a_sync.a_sync.method module
ASyncBoundMethod
ASyncBoundMethod.__call__()
ASyncBoundMethod.__init__()
ASyncBoundMethod._asyncify()
ASyncBoundMethod.all()
ASyncBoundMethod.any()
ASyncBoundMethod.map()
ASyncBoundMethod.max()
ASyncBoundMethod.min()
ASyncBoundMethod.sum()
ASyncBoundMethod._async_def
ASyncBoundMethod._async_wrap
ASyncBoundMethod._asyncified
ASyncBoundMethod._await
ASyncBoundMethod._cache_handle
ASyncBoundMethod._is_async_def
ASyncBoundMethod._modified_fn
ASyncBoundMethod._sync_default
ASyncBoundMethod._sync_wrap
ASyncBoundMethod.default
ASyncBoundMethod.fn
ASyncBoundMethod.modifiers
ASyncBoundMethod.wrapped
ASyncBoundMethodAsyncDefault
ASyncBoundMethodAsyncDefault.__call__()
ASyncBoundMethodAsyncDefault.__init__()
ASyncBoundMethodAsyncDefault._asyncify()
ASyncBoundMethodAsyncDefault.all()
ASyncBoundMethodAsyncDefault.any()
ASyncBoundMethodAsyncDefault.map()
ASyncBoundMethodAsyncDefault.max()
ASyncBoundMethodAsyncDefault.min()
ASyncBoundMethodAsyncDefault.sum()
ASyncBoundMethodAsyncDefault._async_def
ASyncBoundMethodAsyncDefault._async_wrap
ASyncBoundMethodAsyncDefault._asyncified
ASyncBoundMethodAsyncDefault._await
ASyncBoundMethodAsyncDefault._cache_handle
ASyncBoundMethodAsyncDefault._is_async_def
ASyncBoundMethodAsyncDefault._modified_fn
ASyncBoundMethodAsyncDefault._sync_default
ASyncBoundMethodAsyncDefault._sync_wrap
ASyncBoundMethodAsyncDefault.default
ASyncBoundMethodAsyncDefault.fn
ASyncBoundMethodAsyncDefault.modifiers
ASyncBoundMethodAsyncDefault.wrapped
ASyncBoundMethodSyncDefault
ASyncBoundMethodSyncDefault.__call__()
ASyncBoundMethodSyncDefault.__init__()
ASyncBoundMethodSyncDefault._asyncify()
ASyncBoundMethodSyncDefault.all()
ASyncBoundMethodSyncDefault.any()
ASyncBoundMethodSyncDefault.map()
ASyncBoundMethodSyncDefault.max()
ASyncBoundMethodSyncDefault.min()
ASyncBoundMethodSyncDefault.sum()
ASyncBoundMethodSyncDefault._async_def
ASyncBoundMethodSyncDefault._async_wrap
ASyncBoundMethodSyncDefault._asyncified
ASyncBoundMethodSyncDefault._await
ASyncBoundMethodSyncDefault._cache_handle
ASyncBoundMethodSyncDefault._is_async_def
ASyncBoundMethodSyncDefault._modified_fn
ASyncBoundMethodSyncDefault._sync_default
ASyncBoundMethodSyncDefault._sync_wrap
ASyncBoundMethodSyncDefault.default
ASyncBoundMethodSyncDefault.fn
ASyncBoundMethodSyncDefault.modifiers
ASyncBoundMethodSyncDefault.wrapped
ASyncMethodDescriptor
ASyncMethodDescriptor.__call__()
ASyncMethodDescriptor.__init__()
ASyncMethodDescriptor._all()
ASyncMethodDescriptor._any()
ASyncMethodDescriptor._asyncify()
ASyncMethodDescriptor._max()
ASyncMethodDescriptor._min()
ASyncMethodDescriptor._sum()
ASyncMethodDescriptor.map()
ASyncMethodDescriptor._await
ASyncMethodDescriptor.all
ASyncMethodDescriptor.any
ASyncMethodDescriptor.default
ASyncMethodDescriptor.field_name
ASyncMethodDescriptor.max
ASyncMethodDescriptor.min
ASyncMethodDescriptor.modifiers
ASyncMethodDescriptor.sum
ASyncMethodDescriptor.wrapped
ASyncMethodDescriptorAsyncDefault
ASyncMethodDescriptorAsyncDefault.__call__()
ASyncMethodDescriptorAsyncDefault.__init__()
ASyncMethodDescriptorAsyncDefault._all()
ASyncMethodDescriptorAsyncDefault._any()
ASyncMethodDescriptorAsyncDefault._asyncify()
ASyncMethodDescriptorAsyncDefault._max()
ASyncMethodDescriptorAsyncDefault._min()
ASyncMethodDescriptorAsyncDefault._sum()
ASyncMethodDescriptorAsyncDefault.map()
ASyncMethodDescriptorAsyncDefault._await
ASyncMethodDescriptorAsyncDefault.all
ASyncMethodDescriptorAsyncDefault.any
ASyncMethodDescriptorAsyncDefault.default
ASyncMethodDescriptorAsyncDefault.field_name
ASyncMethodDescriptorAsyncDefault.max
ASyncMethodDescriptorAsyncDefault.min
ASyncMethodDescriptorAsyncDefault.modifiers
ASyncMethodDescriptorAsyncDefault.sum
ASyncMethodDescriptorAsyncDefault.wrapped
ASyncMethodDescriptorSyncDefault
ASyncMethodDescriptorSyncDefault.__call__()
ASyncMethodDescriptorSyncDefault.__init__()
ASyncMethodDescriptorSyncDefault._all()
ASyncMethodDescriptorSyncDefault._any()
ASyncMethodDescriptorSyncDefault._asyncify()
ASyncMethodDescriptorSyncDefault._max()
ASyncMethodDescriptorSyncDefault._min()
ASyncMethodDescriptorSyncDefault._sum()
ASyncMethodDescriptorSyncDefault.map()
ASyncMethodDescriptorSyncDefault._await
ASyncMethodDescriptorSyncDefault.all
ASyncMethodDescriptorSyncDefault.any
ASyncMethodDescriptorSyncDefault.default
ASyncMethodDescriptorSyncDefault.field_name
ASyncMethodDescriptorSyncDefault.max
ASyncMethodDescriptorSyncDefault.min
ASyncMethodDescriptorSyncDefault.modifiers
ASyncMethodDescriptorSyncDefault.sum
ASyncMethodDescriptorSyncDefault.wrapped
- a_sync.a_sync.property module
ASyncCachedPropertyDescriptor
ASyncCachedPropertyDescriptor.__init__()
ASyncCachedPropertyDescriptor._all()
ASyncCachedPropertyDescriptor._any()
ASyncCachedPropertyDescriptor._asyncify()
ASyncCachedPropertyDescriptor._check_method_name()
ASyncCachedPropertyDescriptor._check_method_sync()
ASyncCachedPropertyDescriptor._max()
ASyncCachedPropertyDescriptor._min()
ASyncCachedPropertyDescriptor._sum()
ASyncCachedPropertyDescriptor.already_loaded()
ASyncCachedPropertyDescriptor.del_cache_value()
ASyncCachedPropertyDescriptor.deleter()
ASyncCachedPropertyDescriptor.get()
ASyncCachedPropertyDescriptor.get_cache()
ASyncCachedPropertyDescriptor.get_cache_value()
ASyncCachedPropertyDescriptor.get_instance_state()
ASyncCachedPropertyDescriptor.get_loader()
ASyncCachedPropertyDescriptor.get_lock()
ASyncCachedPropertyDescriptor.has_cache_value()
ASyncCachedPropertyDescriptor.map()
ASyncCachedPropertyDescriptor.not_loaded()
ASyncCachedPropertyDescriptor.pop_lock()
ASyncCachedPropertyDescriptor.set_cache_value()
ASyncCachedPropertyDescriptor.setter()
ASyncCachedPropertyDescriptor._TaskMapping
ASyncCachedPropertyDescriptor._await
ASyncCachedPropertyDescriptor.all
ASyncCachedPropertyDescriptor.any
ASyncCachedPropertyDescriptor.default
ASyncCachedPropertyDescriptor.field_name
ASyncCachedPropertyDescriptor.hidden_method_descriptor
ASyncCachedPropertyDescriptor.hidden_method_name
ASyncCachedPropertyDescriptor.max
ASyncCachedPropertyDescriptor.min
ASyncCachedPropertyDescriptor.modifiers
ASyncCachedPropertyDescriptor.sum
ASyncCachedPropertyDescriptor.wrapped
ASyncCachedPropertyDescriptorAsyncDefault
ASyncCachedPropertyDescriptorAsyncDefault.__init__()
ASyncCachedPropertyDescriptorAsyncDefault._all()
ASyncCachedPropertyDescriptorAsyncDefault._any()
ASyncCachedPropertyDescriptorAsyncDefault._asyncify()
ASyncCachedPropertyDescriptorAsyncDefault._check_method_name()
ASyncCachedPropertyDescriptorAsyncDefault._check_method_sync()
ASyncCachedPropertyDescriptorAsyncDefault._max()
ASyncCachedPropertyDescriptorAsyncDefault._min()
ASyncCachedPropertyDescriptorAsyncDefault._sum()
ASyncCachedPropertyDescriptorAsyncDefault.already_loaded()
ASyncCachedPropertyDescriptorAsyncDefault.del_cache_value()
ASyncCachedPropertyDescriptorAsyncDefault.deleter()
ASyncCachedPropertyDescriptorAsyncDefault.get()
ASyncCachedPropertyDescriptorAsyncDefault.get_cache()
ASyncCachedPropertyDescriptorAsyncDefault.get_cache_value()
ASyncCachedPropertyDescriptorAsyncDefault.get_instance_state()
ASyncCachedPropertyDescriptorAsyncDefault.get_loader()
ASyncCachedPropertyDescriptorAsyncDefault.get_lock()
ASyncCachedPropertyDescriptorAsyncDefault.has_cache_value()
ASyncCachedPropertyDescriptorAsyncDefault.map()
ASyncCachedPropertyDescriptorAsyncDefault.not_loaded()
ASyncCachedPropertyDescriptorAsyncDefault.pop_lock()
ASyncCachedPropertyDescriptorAsyncDefault.set_cache_value()
ASyncCachedPropertyDescriptorAsyncDefault.setter()
ASyncCachedPropertyDescriptorAsyncDefault._TaskMapping
ASyncCachedPropertyDescriptorAsyncDefault._await
ASyncCachedPropertyDescriptorAsyncDefault.all
ASyncCachedPropertyDescriptorAsyncDefault.any
ASyncCachedPropertyDescriptorAsyncDefault.default
ASyncCachedPropertyDescriptorAsyncDefault.field_name
ASyncCachedPropertyDescriptorAsyncDefault.hidden_method_descriptor
ASyncCachedPropertyDescriptorAsyncDefault.hidden_method_name
ASyncCachedPropertyDescriptorAsyncDefault.max
ASyncCachedPropertyDescriptorAsyncDefault.min
ASyncCachedPropertyDescriptorAsyncDefault.modifiers
ASyncCachedPropertyDescriptorAsyncDefault.sum
ASyncCachedPropertyDescriptorAsyncDefault.wrapped
ASyncCachedPropertyDescriptorSyncDefault
ASyncCachedPropertyDescriptorSyncDefault.__init__()
ASyncCachedPropertyDescriptorSyncDefault._all()
ASyncCachedPropertyDescriptorSyncDefault._any()
ASyncCachedPropertyDescriptorSyncDefault._asyncify()
ASyncCachedPropertyDescriptorSyncDefault._check_method_name()
ASyncCachedPropertyDescriptorSyncDefault._check_method_sync()
ASyncCachedPropertyDescriptorSyncDefault._max()
ASyncCachedPropertyDescriptorSyncDefault._min()
ASyncCachedPropertyDescriptorSyncDefault._sum()
ASyncCachedPropertyDescriptorSyncDefault.already_loaded()
ASyncCachedPropertyDescriptorSyncDefault.del_cache_value()
ASyncCachedPropertyDescriptorSyncDefault.deleter()
ASyncCachedPropertyDescriptorSyncDefault.get()
ASyncCachedPropertyDescriptorSyncDefault.get_cache()
ASyncCachedPropertyDescriptorSyncDefault.get_cache_value()
ASyncCachedPropertyDescriptorSyncDefault.get_instance_state()
ASyncCachedPropertyDescriptorSyncDefault.get_loader()
ASyncCachedPropertyDescriptorSyncDefault.get_lock()
ASyncCachedPropertyDescriptorSyncDefault.has_cache_value()
ASyncCachedPropertyDescriptorSyncDefault.map()
ASyncCachedPropertyDescriptorSyncDefault.not_loaded()
ASyncCachedPropertyDescriptorSyncDefault.pop_lock()
ASyncCachedPropertyDescriptorSyncDefault.set_cache_value()
ASyncCachedPropertyDescriptorSyncDefault.setter()
ASyncCachedPropertyDescriptorSyncDefault._TaskMapping
ASyncCachedPropertyDescriptorSyncDefault._await
ASyncCachedPropertyDescriptorSyncDefault.all
ASyncCachedPropertyDescriptorSyncDefault.any
ASyncCachedPropertyDescriptorSyncDefault.default
ASyncCachedPropertyDescriptorSyncDefault.field_name
ASyncCachedPropertyDescriptorSyncDefault.hidden_method_descriptor
ASyncCachedPropertyDescriptorSyncDefault.hidden_method_name
ASyncCachedPropertyDescriptorSyncDefault.max
ASyncCachedPropertyDescriptorSyncDefault.min
ASyncCachedPropertyDescriptorSyncDefault.modifiers
ASyncCachedPropertyDescriptorSyncDefault.sum
ASyncCachedPropertyDescriptorSyncDefault.wrapped
ASyncPropertyDescriptor
ASyncPropertyDescriptor.__init__()
ASyncPropertyDescriptor._all()
ASyncPropertyDescriptor._any()
ASyncPropertyDescriptor._asyncify()
ASyncPropertyDescriptor._max()
ASyncPropertyDescriptor._min()
ASyncPropertyDescriptor._sum()
ASyncPropertyDescriptor.awaitable_only()
ASyncPropertyDescriptor.get()
ASyncPropertyDescriptor.get_loader()
ASyncPropertyDescriptor.map()
ASyncPropertyDescriptor._TaskMapping
ASyncPropertyDescriptor._await
ASyncPropertyDescriptor.all
ASyncPropertyDescriptor.any
ASyncPropertyDescriptor.default
ASyncPropertyDescriptor.field_name
ASyncPropertyDescriptor.hidden_method_descriptor
ASyncPropertyDescriptor.hidden_method_name
ASyncPropertyDescriptor.max
ASyncPropertyDescriptor.min
ASyncPropertyDescriptor.modifiers
ASyncPropertyDescriptor.sum
ASyncPropertyDescriptor.wrapped
ASyncPropertyDescriptorAsyncDefault
ASyncPropertyDescriptorAsyncDefault.__init__()
ASyncPropertyDescriptorAsyncDefault._all()
ASyncPropertyDescriptorAsyncDefault._any()
ASyncPropertyDescriptorAsyncDefault._asyncify()
ASyncPropertyDescriptorAsyncDefault._max()
ASyncPropertyDescriptorAsyncDefault._min()
ASyncPropertyDescriptorAsyncDefault._sum()
ASyncPropertyDescriptorAsyncDefault.awaitable_only()
ASyncPropertyDescriptorAsyncDefault.get()
ASyncPropertyDescriptorAsyncDefault.get_loader()
ASyncPropertyDescriptorAsyncDefault.map()
ASyncPropertyDescriptorAsyncDefault._TaskMapping
ASyncPropertyDescriptorAsyncDefault._await
ASyncPropertyDescriptorAsyncDefault.all
ASyncPropertyDescriptorAsyncDefault.any
ASyncPropertyDescriptorAsyncDefault.default
ASyncPropertyDescriptorAsyncDefault.field_name
ASyncPropertyDescriptorAsyncDefault.hidden_method_descriptor
ASyncPropertyDescriptorAsyncDefault.hidden_method_name
ASyncPropertyDescriptorAsyncDefault.max
ASyncPropertyDescriptorAsyncDefault.min
ASyncPropertyDescriptorAsyncDefault.modifiers
ASyncPropertyDescriptorAsyncDefault.sum
ASyncPropertyDescriptorAsyncDefault.wrapped
ASyncPropertyDescriptorSyncDefault
ASyncPropertyDescriptorSyncDefault.__init__()
ASyncPropertyDescriptorSyncDefault._all()
ASyncPropertyDescriptorSyncDefault._any()
ASyncPropertyDescriptorSyncDefault._asyncify()
ASyncPropertyDescriptorSyncDefault._max()
ASyncPropertyDescriptorSyncDefault._min()
ASyncPropertyDescriptorSyncDefault._sum()
ASyncPropertyDescriptorSyncDefault.awaitable_only()
ASyncPropertyDescriptorSyncDefault.get()
ASyncPropertyDescriptorSyncDefault.get_loader()
ASyncPropertyDescriptorSyncDefault.map()
ASyncPropertyDescriptorSyncDefault._TaskMapping
ASyncPropertyDescriptorSyncDefault._await
ASyncPropertyDescriptorSyncDefault.all
ASyncPropertyDescriptorSyncDefault.any
ASyncPropertyDescriptorSyncDefault.default
ASyncPropertyDescriptorSyncDefault.field_name
ASyncPropertyDescriptorSyncDefault.hidden_method_descriptor
ASyncPropertyDescriptorSyncDefault.hidden_method_name
ASyncPropertyDescriptorSyncDefault.max
ASyncPropertyDescriptorSyncDefault.min
ASyncPropertyDescriptorSyncDefault.modifiers
ASyncPropertyDescriptorSyncDefault.sum
ASyncPropertyDescriptorSyncDefault.wrapped
HiddenMethod
HiddenMethod.__call__()
HiddenMethod.__init__()
HiddenMethod._asyncify()
HiddenMethod.all()
HiddenMethod.any()
HiddenMethod.map()
HiddenMethod.max()
HiddenMethod.min()
HiddenMethod.sum()
HiddenMethod._async_def
HiddenMethod._async_wrap
HiddenMethod._asyncified
HiddenMethod._await
HiddenMethod._cache_handle
HiddenMethod._is_async_def
HiddenMethod._modified_fn
HiddenMethod._sync_default
HiddenMethod._sync_wrap
HiddenMethod.default
HiddenMethod.fn
HiddenMethod.modifiers
HiddenMethod.wrapped
HiddenMethodDescriptor
HiddenMethodDescriptor.__call__()
HiddenMethodDescriptor.__init__()
HiddenMethodDescriptor._all()
HiddenMethodDescriptor._any()
HiddenMethodDescriptor._asyncify()
HiddenMethodDescriptor._max()
HiddenMethodDescriptor._min()
HiddenMethodDescriptor._sum()
HiddenMethodDescriptor.map()
HiddenMethodDescriptor._await
HiddenMethodDescriptor.all
HiddenMethodDescriptor.any
HiddenMethodDescriptor.default
HiddenMethodDescriptor.field_name
HiddenMethodDescriptor.max
HiddenMethodDescriptor.min
HiddenMethodDescriptor.modifiers
HiddenMethodDescriptor.sum
HiddenMethodDescriptor.wrapped
_ASyncPropertyDescriptorBase
_ASyncPropertyDescriptorBase.__init__()
_ASyncPropertyDescriptorBase._all()
_ASyncPropertyDescriptorBase._any()
_ASyncPropertyDescriptorBase._asyncify()
_ASyncPropertyDescriptorBase._max()
_ASyncPropertyDescriptorBase._min()
_ASyncPropertyDescriptorBase._sum()
_ASyncPropertyDescriptorBase.get()
_ASyncPropertyDescriptorBase.map()
_ASyncPropertyDescriptorBase._TaskMapping
_ASyncPropertyDescriptorBase._await
_ASyncPropertyDescriptorBase.all
_ASyncPropertyDescriptorBase.any
_ASyncPropertyDescriptorBase.default
_ASyncPropertyDescriptorBase.field_name
_ASyncPropertyDescriptorBase.hidden_method_descriptor
_ASyncPropertyDescriptorBase.hidden_method_name
_ASyncPropertyDescriptorBase.max
_ASyncPropertyDescriptorBase.min
_ASyncPropertyDescriptorBase.modifiers
_ASyncPropertyDescriptorBase.sum
_ASyncPropertyDescriptorBase.wrapped
cached_property
cached_property.__init__()
cached_property._all()
cached_property._any()
cached_property._asyncify()
cached_property._check_method_name()
cached_property._check_method_sync()
cached_property._max()
cached_property._min()
cached_property._sum()
cached_property.already_loaded()
cached_property.del_cache_value()
cached_property.deleter()
cached_property.get()
cached_property.get_cache()
cached_property.get_cache_value()
cached_property.get_instance_state()
cached_property.get_loader()
cached_property.get_lock()
cached_property.has_cache_value()
cached_property.map()
cached_property.not_loaded()
cached_property.pop_lock()
cached_property.set_cache_value()
cached_property.setter()
cached_property._TaskMapping
cached_property._await
cached_property.all
cached_property.any
cached_property.default
cached_property.field_name
cached_property.hidden_method_descriptor
cached_property.hidden_method_name
cached_property.max
cached_property.min
cached_property.modifiers
cached_property.sum
cached_property.wrapped
property
property.__init__()
property._all()
property._any()
property._asyncify()
property._max()
property._min()
property._sum()
property.awaitable_only()
property.get()
property.get_loader()
property.map()
property._TaskMapping
property._await
property.all
property.any
property.default
property.field_name
property.hidden_method_descriptor
property.hidden_method_name
property.max
property.min
property.modifiers
property.sum
property.wrapped
_parse_args()
a_sync_cached_property()
a_sync_property()
- a_sync.a_sync.singleton module
- Module contents
ASyncCachedPropertyDescriptor
ASyncCachedPropertyDescriptor.__init__()
ASyncCachedPropertyDescriptor._all()
ASyncCachedPropertyDescriptor._any()
ASyncCachedPropertyDescriptor._asyncify()
ASyncCachedPropertyDescriptor._check_method_name()
ASyncCachedPropertyDescriptor._check_method_sync()
ASyncCachedPropertyDescriptor._max()
ASyncCachedPropertyDescriptor._min()
ASyncCachedPropertyDescriptor._sum()
ASyncCachedPropertyDescriptor.already_loaded()
ASyncCachedPropertyDescriptor.del_cache_value()
ASyncCachedPropertyDescriptor.deleter()
ASyncCachedPropertyDescriptor.get()
ASyncCachedPropertyDescriptor.get_cache()
ASyncCachedPropertyDescriptor.get_cache_value()
ASyncCachedPropertyDescriptor.get_instance_state()
ASyncCachedPropertyDescriptor.get_loader()
ASyncCachedPropertyDescriptor.get_lock()
ASyncCachedPropertyDescriptor.has_cache_value()
ASyncCachedPropertyDescriptor.map()
ASyncCachedPropertyDescriptor.not_loaded()
ASyncCachedPropertyDescriptor.pop_lock()
ASyncCachedPropertyDescriptor.set_cache_value()
ASyncCachedPropertyDescriptor.setter()
ASyncCachedPropertyDescriptor._TaskMapping
ASyncCachedPropertyDescriptor._await
ASyncCachedPropertyDescriptor.all
ASyncCachedPropertyDescriptor.any
ASyncCachedPropertyDescriptor.default
ASyncCachedPropertyDescriptor.field_name
ASyncCachedPropertyDescriptor.hidden_method_descriptor
ASyncCachedPropertyDescriptor.hidden_method_name
ASyncCachedPropertyDescriptor.max
ASyncCachedPropertyDescriptor.min
ASyncCachedPropertyDescriptor.modifiers
ASyncCachedPropertyDescriptor.sum
ASyncCachedPropertyDescriptor.wrapped
ASyncFunction
ASyncFunction.__call__()
ASyncFunction.__init__()
ASyncFunction._asyncify()
ASyncFunction.all()
ASyncFunction.any()
ASyncFunction.map()
ASyncFunction.max()
ASyncFunction.min()
ASyncFunction.sum()
ASyncFunction._async_def
ASyncFunction._async_wrap
ASyncFunction._asyncified
ASyncFunction._await
ASyncFunction._modified_fn
ASyncFunction._sync_default
ASyncFunction._sync_wrap
ASyncFunction.default
ASyncFunction.fn
ASyncFunction.modifiers
ASyncFunction.wrapped
ASyncGenericBase
ASyncPropertyDescriptor
ASyncPropertyDescriptor.__init__()
ASyncPropertyDescriptor._all()
ASyncPropertyDescriptor._any()
ASyncPropertyDescriptor._asyncify()
ASyncPropertyDescriptor._max()
ASyncPropertyDescriptor._min()
ASyncPropertyDescriptor._sum()
ASyncPropertyDescriptor.awaitable_only()
ASyncPropertyDescriptor.get()
ASyncPropertyDescriptor.get_loader()
ASyncPropertyDescriptor.map()
ASyncPropertyDescriptor._TaskMapping
ASyncPropertyDescriptor._await
ASyncPropertyDescriptor.all
ASyncPropertyDescriptor.any
ASyncPropertyDescriptor.default
ASyncPropertyDescriptor.field_name
ASyncPropertyDescriptor.hidden_method_descriptor
ASyncPropertyDescriptor.hidden_method_name
ASyncPropertyDescriptor.max
ASyncPropertyDescriptor.min
ASyncPropertyDescriptor.modifiers
ASyncPropertyDescriptor.sum
ASyncPropertyDescriptor.wrapped
HiddenMethod
HiddenMethod.__call__()
HiddenMethod.__init__()
HiddenMethod._asyncify()
HiddenMethod.all()
HiddenMethod.any()
HiddenMethod.map()
HiddenMethod.max()
HiddenMethod.min()
HiddenMethod.sum()
HiddenMethod._async_def
HiddenMethod._async_wrap
HiddenMethod._asyncified
HiddenMethod._await
HiddenMethod._cache_handle
HiddenMethod._is_async_def
HiddenMethod._modified_fn
HiddenMethod._sync_default
HiddenMethod._sync_wrap
HiddenMethod.default
HiddenMethod.fn
HiddenMethod.modifiers
HiddenMethod.wrapped
HiddenMethodDescriptor
HiddenMethodDescriptor.__call__()
HiddenMethodDescriptor.__init__()
HiddenMethodDescriptor._all()
HiddenMethodDescriptor._any()
HiddenMethodDescriptor._asyncify()
HiddenMethodDescriptor._max()
HiddenMethodDescriptor._min()
HiddenMethodDescriptor._sum()
HiddenMethodDescriptor.map()
HiddenMethodDescriptor._await
HiddenMethodDescriptor.all
HiddenMethodDescriptor.any
HiddenMethodDescriptor.default
HiddenMethodDescriptor.field_name
HiddenMethodDescriptor.max
HiddenMethodDescriptor.min
HiddenMethodDescriptor.modifiers
HiddenMethodDescriptor.sum
HiddenMethodDescriptor.wrapped
cached_property
cached_property.__init__()
cached_property._all()
cached_property._any()
cached_property._asyncify()
cached_property._check_method_name()
cached_property._check_method_sync()
cached_property._max()
cached_property._min()
cached_property._sum()
cached_property.already_loaded()
cached_property.del_cache_value()
cached_property.deleter()
cached_property.get()
cached_property.get_cache()
cached_property.get_cache_value()
cached_property.get_instance_state()
cached_property.get_loader()
cached_property.get_lock()
cached_property.has_cache_value()
cached_property.map()
cached_property.not_loaded()
cached_property.pop_lock()
cached_property.set_cache_value()
cached_property.setter()
cached_property._TaskMapping
cached_property._await
cached_property.all
cached_property.any
cached_property.default
cached_property.field_name
cached_property.hidden_method_descriptor
cached_property.hidden_method_name
cached_property.max
cached_property.min
cached_property.modifiers
cached_property.sum
cached_property.wrapped
property
property.__init__()
property._all()
property._any()
property._asyncify()
property._max()
property._min()
property._sum()
property.awaitable_only()
property.get()
property.get_loader()
property.map()
property._TaskMapping
property._await
property.all
property.any
property.default
property.field_name
property.hidden_method_descriptor
property.hidden_method_name
property.max
property.min
property.modifiers
property.sum
property.wrapped
a_sync()
- a_sync.asyncio package
- a_sync.primitives package
- Subpackages
- Submodules
- a_sync.primitives._debug module
- a_sync.primitives._loggable module
- a_sync.primitives.queue module
PriorityProcessingQueue
PriorityProcessingQueue.__call__()
PriorityProcessingQueue.__init__()
PriorityProcessingQueue._create_future()
PriorityProcessingQueue._ensure_workers()
PriorityProcessingQueue._format()
PriorityProcessingQueue._get()
PriorityProcessingQueue._get_loop()
PriorityProcessingQueue._init()
PriorityProcessingQueue._put()
PriorityProcessingQueue._wakeup_next()
PriorityProcessingQueue.close()
PriorityProcessingQueue.empty()
PriorityProcessingQueue.full()
PriorityProcessingQueue.get()
PriorityProcessingQueue.get_nowait()
PriorityProcessingQueue.join()
PriorityProcessingQueue.put()
PriorityProcessingQueue.put_nowait()
PriorityProcessingQueue.qsize()
PriorityProcessingQueue.task_done()
PriorityProcessingQueue._closed
PriorityProcessingQueue._finished
PriorityProcessingQueue._getters
PriorityProcessingQueue._loop
PriorityProcessingQueue._maxsize
PriorityProcessingQueue._name
PriorityProcessingQueue._no_futs
PriorityProcessingQueue._putters
PriorityProcessingQueue._queue
PriorityProcessingQueue._unfinished_tasks
PriorityProcessingQueue._worker_coro
PriorityProcessingQueue._workers
PriorityProcessingQueue.func
PriorityProcessingQueue.maxsize
PriorityProcessingQueue.name
PriorityProcessingQueue.num_workers
ProcessingQueue
ProcessingQueue.__call__()
ProcessingQueue.__init__()
ProcessingQueue._create_future()
ProcessingQueue._ensure_workers()
ProcessingQueue._format()
ProcessingQueue._get()
ProcessingQueue._get_loop()
ProcessingQueue._init()
ProcessingQueue._put()
ProcessingQueue._wakeup_next()
ProcessingQueue.close()
ProcessingQueue.empty()
ProcessingQueue.full()
ProcessingQueue.get()
ProcessingQueue.get_nowait()
ProcessingQueue.join()
ProcessingQueue.put()
ProcessingQueue.put_nowait()
ProcessingQueue.qsize()
ProcessingQueue.task_done()
ProcessingQueue._closed
ProcessingQueue._finished
ProcessingQueue._getters
ProcessingQueue._loop
ProcessingQueue._maxsize
ProcessingQueue._name
ProcessingQueue._no_futs
ProcessingQueue._putters
ProcessingQueue._queue
ProcessingQueue._unfinished_tasks
ProcessingQueue._worker_coro
ProcessingQueue._workers
ProcessingQueue.func
ProcessingQueue.maxsize
ProcessingQueue.name
ProcessingQueue.num_workers
Queue
Queue.__init__()
Queue._format()
Queue._get()
Queue._get_loop()
Queue._init()
Queue._put()
Queue._wakeup_next()
Queue.empty()
Queue.full()
Queue.get()
Queue.get_all()
Queue.get_all_nowait()
Queue.get_multi()
Queue.get_multi_nowait()
Queue.get_nowait()
Queue.join()
Queue.put()
Queue.put_nowait()
Queue.qsize()
Queue.task_done()
Queue._finished
Queue._getters
Queue._loop
Queue._maxsize
Queue._putters
Queue._queue
Queue._unfinished_tasks
Queue.maxsize
SmartProcessingQueue
SmartProcessingQueue.__call__()
SmartProcessingQueue.__init__()
SmartProcessingQueue._create_future()
SmartProcessingQueue._ensure_workers()
SmartProcessingQueue._format()
SmartProcessingQueue._get()
SmartProcessingQueue._get_key()
SmartProcessingQueue._get_loop()
SmartProcessingQueue._init()
SmartProcessingQueue._put()
SmartProcessingQueue._wakeup_next()
SmartProcessingQueue.close()
SmartProcessingQueue.empty()
SmartProcessingQueue.full()
SmartProcessingQueue.get()
SmartProcessingQueue.get_nowait()
SmartProcessingQueue.join()
SmartProcessingQueue.put()
SmartProcessingQueue.put_nowait()
SmartProcessingQueue.qsize()
SmartProcessingQueue.task_done()
SmartProcessingQueue._closed
SmartProcessingQueue._finished
SmartProcessingQueue._futs
SmartProcessingQueue._getters
SmartProcessingQueue._loop
SmartProcessingQueue._maxsize
SmartProcessingQueue._name
SmartProcessingQueue._no_futs
SmartProcessingQueue._putters
SmartProcessingQueue._queue
SmartProcessingQueue._unfinished_tasks
SmartProcessingQueue._worker_coro
SmartProcessingQueue._workers
SmartProcessingQueue.func
SmartProcessingQueue.maxsize
SmartProcessingQueue.name
SmartProcessingQueue.num_workers
VariablePriorityQueue
VariablePriorityQueue.__init__()
VariablePriorityQueue._format()
VariablePriorityQueue._get()
VariablePriorityQueue._get_key()
VariablePriorityQueue._get_loop()
VariablePriorityQueue._init()
VariablePriorityQueue._put()
VariablePriorityQueue._wakeup_next()
VariablePriorityQueue.empty()
VariablePriorityQueue.full()
VariablePriorityQueue.get()
VariablePriorityQueue.get_nowait()
VariablePriorityQueue.join()
VariablePriorityQueue.put()
VariablePriorityQueue.put_nowait()
VariablePriorityQueue.qsize()
VariablePriorityQueue.task_done()
VariablePriorityQueue._loop
VariablePriorityQueue.maxsize
_PriorityQueueMixin
_Queue
_Queue.__init__()
_Queue._format()
_Queue._get()
_Queue._get_loop()
_Queue._init()
_Queue._put()
_Queue._wakeup_next()
_Queue.empty()
_Queue.full()
_Queue.get()
_Queue.get_nowait()
_Queue.join()
_Queue.put()
_Queue.put_nowait()
_Queue.qsize()
_Queue.task_done()
_Queue._finished
_Queue._getters
_Queue._loop
_Queue._maxsize
_Queue._putters
_Queue._queue
_Queue._unfinished_tasks
_Queue.maxsize
_SmartFutureRef
_VariablePriorityQueueMixin
_validate_args()
- Module contents
CounterLock
CounterLock.__init__()
CounterLock._debug_daemon()
CounterLock._ensure_debug_daemon()
CounterLock._get_loop()
CounterLock._start_debug_daemon()
CounterLock._stop_debug_daemon()
CounterLock.is_ready()
CounterLock.set()
CounterLock.wait_for()
CounterLock._loop
CounterLock._name
CounterLock.debug_logs_enabled
CounterLock.logger
CounterLock.value
Event
PrioritySemaphore
PrioritySemaphore.__call__()
PrioritySemaphore.__getitem__()
PrioritySemaphore.__init__()
PrioritySemaphore._debug_daemon()
PrioritySemaphore._ensure_debug_daemon()
PrioritySemaphore._get_loop()
PrioritySemaphore._start_debug_daemon()
PrioritySemaphore._stop_debug_daemon()
PrioritySemaphore._wake_up_next()
PrioritySemaphore.acquire()
PrioritySemaphore.decorate()
PrioritySemaphore.locked()
PrioritySemaphore.release()
PrioritySemaphore._loop
PrioritySemaphore._value
PrioritySemaphore._waiters
PrioritySemaphore.debug_logs_enabled
PrioritySemaphore.logger
PrioritySemaphore.name
ProcessingQueue
ProcessingQueue.__call__()
ProcessingQueue.__init__()
ProcessingQueue._create_future()
ProcessingQueue._ensure_workers()
ProcessingQueue._format()
ProcessingQueue._get()
ProcessingQueue._get_loop()
ProcessingQueue._init()
ProcessingQueue._put()
ProcessingQueue._wakeup_next()
ProcessingQueue.close()
ProcessingQueue.empty()
ProcessingQueue.full()
ProcessingQueue.get()
ProcessingQueue.get_nowait()
ProcessingQueue.join()
ProcessingQueue.put()
ProcessingQueue.put_nowait()
ProcessingQueue.qsize()
ProcessingQueue.task_done()
ProcessingQueue._closed
ProcessingQueue._finished
ProcessingQueue._getters
ProcessingQueue._loop
ProcessingQueue._maxsize
ProcessingQueue._name
ProcessingQueue._no_futs
ProcessingQueue._putters
ProcessingQueue._queue
ProcessingQueue._unfinished_tasks
ProcessingQueue._worker_coro
ProcessingQueue._workers
ProcessingQueue.func
ProcessingQueue.maxsize
ProcessingQueue.name
ProcessingQueue.num_workers
Queue
Queue.__init__()
Queue._format()
Queue._get()
Queue._get_loop()
Queue._init()
Queue._put()
Queue._wakeup_next()
Queue.empty()
Queue.full()
Queue.get()
Queue.get_all()
Queue.get_all_nowait()
Queue.get_multi()
Queue.get_multi_nowait()
Queue.get_nowait()
Queue.join()
Queue.put()
Queue.put_nowait()
Queue.qsize()
Queue.task_done()
Queue._finished
Queue._getters
Queue._loop
Queue._maxsize
Queue._putters
Queue._queue
Queue._unfinished_tasks
Queue.maxsize
Semaphore
Semaphore.__call__()
Semaphore.__init__()
Semaphore._debug_daemon()
Semaphore._ensure_debug_daemon()
Semaphore._get_loop()
Semaphore._start_debug_daemon()
Semaphore._stop_debug_daemon()
Semaphore._wake_up_next()
Semaphore.acquire()
Semaphore.decorate()
Semaphore.locked()
Semaphore.release()
Semaphore._loop
Semaphore._value
Semaphore._waiters
Semaphore.debug_logs_enabled
Semaphore.logger
Semaphore.name
SmartProcessingQueue
SmartProcessingQueue.__call__()
SmartProcessingQueue.__init__()
SmartProcessingQueue._create_future()
SmartProcessingQueue._ensure_workers()
SmartProcessingQueue._format()
SmartProcessingQueue._get()
SmartProcessingQueue._get_key()
SmartProcessingQueue._get_loop()
SmartProcessingQueue._init()
SmartProcessingQueue._put()
SmartProcessingQueue._wakeup_next()
SmartProcessingQueue.close()
SmartProcessingQueue.empty()
SmartProcessingQueue.full()
SmartProcessingQueue.get()
SmartProcessingQueue.get_nowait()
SmartProcessingQueue.join()
SmartProcessingQueue.put()
SmartProcessingQueue.put_nowait()
SmartProcessingQueue.qsize()
SmartProcessingQueue.task_done()
SmartProcessingQueue._closed
SmartProcessingQueue._finished
SmartProcessingQueue._futs
SmartProcessingQueue._getters
SmartProcessingQueue._loop
SmartProcessingQueue._maxsize
SmartProcessingQueue._name
SmartProcessingQueue._no_futs
SmartProcessingQueue._putters
SmartProcessingQueue._queue
SmartProcessingQueue._unfinished_tasks
SmartProcessingQueue._worker_coro
SmartProcessingQueue._workers
SmartProcessingQueue.func
SmartProcessingQueue.maxsize
SmartProcessingQueue.name
SmartProcessingQueue.num_workers
ThreadsafeSemaphore
ThreadsafeSemaphore.__call__()
ThreadsafeSemaphore.__init__()
ThreadsafeSemaphore._debug_daemon()
ThreadsafeSemaphore._ensure_debug_daemon()
ThreadsafeSemaphore._get_loop()
ThreadsafeSemaphore._start_debug_daemon()
ThreadsafeSemaphore._stop_debug_daemon()
ThreadsafeSemaphore._wake_up_next()
ThreadsafeSemaphore.acquire()
ThreadsafeSemaphore.decorate()
ThreadsafeSemaphore.locked()
ThreadsafeSemaphore.release()
ThreadsafeSemaphore._loop
ThreadsafeSemaphore._value
ThreadsafeSemaphore._waiters
ThreadsafeSemaphore.debug_logs_enabled
ThreadsafeSemaphore.logger
ThreadsafeSemaphore.name
ThreadsafeSemaphore.semaphore
- a_sync.sphinx package
- Submodules
- a_sync.sphinx.ext module
- Introduction
ASyncDescriptorDirective
ASyncDescriptorDirective.__init__()
ASyncDescriptorDirective._object_hierarchy_parts()
ASyncDescriptorDirective._toc_entry_name()
ASyncDescriptorDirective.add_name()
ASyncDescriptorDirective.add_target_and_index()
ASyncDescriptorDirective.after_content()
ASyncDescriptorDirective.assert_has_content()
ASyncDescriptorDirective.before_content()
ASyncDescriptorDirective.debug()
ASyncDescriptorDirective.directive_error()
ASyncDescriptorDirective.error()
ASyncDescriptorDirective.get_field_type_map()
ASyncDescriptorDirective.get_index_text()
ASyncDescriptorDirective.get_location()
ASyncDescriptorDirective.get_signature_prefix()
ASyncDescriptorDirective.get_signatures()
ASyncDescriptorDirective.get_source_info()
ASyncDescriptorDirective.handle_signature()
ASyncDescriptorDirective.info()
ASyncDescriptorDirective.needs_arglist()
ASyncDescriptorDirective.parse_content_to_nodes()
ASyncDescriptorDirective.parse_inline()
ASyncDescriptorDirective.parse_text_to_nodes()
ASyncDescriptorDirective.run()
ASyncDescriptorDirective.set_source_info()
ASyncDescriptorDirective.severe()
ASyncDescriptorDirective.transform_content()
ASyncDescriptorDirective.warning()
ASyncDescriptorDirective._doc_field_type_map
ASyncDescriptorDirective.allow_nesting
ASyncDescriptorDirective.config
ASyncDescriptorDirective.doc_field_types
ASyncDescriptorDirective.domain
ASyncDescriptorDirective.env
ASyncDescriptorDirective.final_argument_whitespace
ASyncDescriptorDirective.has_content
ASyncDescriptorDirective.indexnode
ASyncDescriptorDirective.objtype
ASyncDescriptorDirective.option_spec
ASyncDescriptorDirective.optional_arguments
ASyncDescriptorDirective.prefix_env
ASyncDescriptorDirective.required_arguments
ASyncDescriptorDocumenter
ASyncDescriptorDocumenter.typ
ASyncDescriptorDocumenter.__init__()
ASyncDescriptorDocumenter._call_format_args()
ASyncDescriptorDocumenter._find_signature()
ASyncDescriptorDocumenter.add_content()
ASyncDescriptorDocumenter.add_directive_header()
ASyncDescriptorDocumenter.add_line()
ASyncDescriptorDocumenter.annotate_to_first_argument()
ASyncDescriptorDocumenter.can_document_member()
ASyncDescriptorDocumenter.check_module()
ASyncDescriptorDocumenter.document_members()
ASyncDescriptorDocumenter.filter_members()
ASyncDescriptorDocumenter.format_args()
ASyncDescriptorDocumenter.format_name()
ASyncDescriptorDocumenter.format_signature()
ASyncDescriptorDocumenter.generate()
ASyncDescriptorDocumenter.get_attr()
ASyncDescriptorDocumenter.get_doc()
ASyncDescriptorDocumenter.get_object_members()
ASyncDescriptorDocumenter.get_real_modname()
ASyncDescriptorDocumenter.get_sourcename()
ASyncDescriptorDocumenter.import_object()
ASyncDescriptorDocumenter.merge_default_value()
ASyncDescriptorDocumenter.parse_name()
ASyncDescriptorDocumenter.process_doc()
ASyncDescriptorDocumenter.resolve_name()
ASyncDescriptorDocumenter.sort_members()
ASyncDescriptorDocumenter._new_docstrings
ASyncDescriptorDocumenter._signatures
ASyncDescriptorDocumenter.content_indent
ASyncDescriptorDocumenter.directivetype
ASyncDescriptorDocumenter.documenters
ASyncDescriptorDocumenter.member_order
ASyncDescriptorDocumenter.objtype
ASyncDescriptorDocumenter.option_spec
ASyncDescriptorDocumenter.priority
ASyncDescriptorDocumenter.titles_allowed
ASyncFunctionAsyncDirective
ASyncFunctionAsyncDirective.__init__()
ASyncFunctionAsyncDirective._object_hierarchy_parts()
ASyncFunctionAsyncDirective._toc_entry_name()
ASyncFunctionAsyncDirective.add_name()
ASyncFunctionAsyncDirective.add_target_and_index()
ASyncFunctionAsyncDirective.after_content()
ASyncFunctionAsyncDirective.assert_has_content()
ASyncFunctionAsyncDirective.before_content()
ASyncFunctionAsyncDirective.debug()
ASyncFunctionAsyncDirective.directive_error()
ASyncFunctionAsyncDirective.error()
ASyncFunctionAsyncDirective.get_field_type_map()
ASyncFunctionAsyncDirective.get_index_text()
ASyncFunctionAsyncDirective.get_location()
ASyncFunctionAsyncDirective.get_signature_prefix()
ASyncFunctionAsyncDirective.get_signatures()
ASyncFunctionAsyncDirective.get_source_info()
ASyncFunctionAsyncDirective.handle_signature()
ASyncFunctionAsyncDirective.info()
ASyncFunctionAsyncDirective.needs_arglist()
ASyncFunctionAsyncDirective.parse_content_to_nodes()
ASyncFunctionAsyncDirective.parse_inline()
ASyncFunctionAsyncDirective.parse_text_to_nodes()
ASyncFunctionAsyncDirective.run()
ASyncFunctionAsyncDirective.set_source_info()
ASyncFunctionAsyncDirective.severe()
ASyncFunctionAsyncDirective.transform_content()
ASyncFunctionAsyncDirective.warning()
ASyncFunctionAsyncDirective._doc_field_type_map
ASyncFunctionAsyncDirective.allow_nesting
ASyncFunctionAsyncDirective.config
ASyncFunctionAsyncDirective.doc_field_types
ASyncFunctionAsyncDirective.domain
ASyncFunctionAsyncDirective.env
ASyncFunctionAsyncDirective.final_argument_whitespace
ASyncFunctionAsyncDirective.has_content
ASyncFunctionAsyncDirective.indexnode
ASyncFunctionAsyncDirective.objtype
ASyncFunctionAsyncDirective.option_spec
ASyncFunctionAsyncDirective.optional_arguments
ASyncFunctionAsyncDirective.prefix_env
ASyncFunctionAsyncDirective.required_arguments
ASyncFunctionAsyncDocumenter
ASyncFunctionAsyncDocumenter.typ
ASyncFunctionAsyncDocumenter.__init__()
ASyncFunctionAsyncDocumenter._call_format_args()
ASyncFunctionAsyncDocumenter._find_signature()
ASyncFunctionAsyncDocumenter.add_content()
ASyncFunctionAsyncDocumenter.add_directive_header()
ASyncFunctionAsyncDocumenter.add_line()
ASyncFunctionAsyncDocumenter.annotate_to_first_argument()
ASyncFunctionAsyncDocumenter.can_document_member()
ASyncFunctionAsyncDocumenter.check_module()
ASyncFunctionAsyncDocumenter.document_members()
ASyncFunctionAsyncDocumenter.filter_members()
ASyncFunctionAsyncDocumenter.format_args()
ASyncFunctionAsyncDocumenter.format_name()
ASyncFunctionAsyncDocumenter.format_signature()
ASyncFunctionAsyncDocumenter.generate()
ASyncFunctionAsyncDocumenter.get_attr()
ASyncFunctionAsyncDocumenter.get_doc()
ASyncFunctionAsyncDocumenter.get_object_members()
ASyncFunctionAsyncDocumenter.get_real_modname()
ASyncFunctionAsyncDocumenter.get_sourcename()
ASyncFunctionAsyncDocumenter.import_object()
ASyncFunctionAsyncDocumenter.merge_default_value()
ASyncFunctionAsyncDocumenter.parse_name()
ASyncFunctionAsyncDocumenter.process_doc()
ASyncFunctionAsyncDocumenter.resolve_name()
ASyncFunctionAsyncDocumenter.sort_members()
ASyncFunctionAsyncDocumenter._new_docstrings
ASyncFunctionAsyncDocumenter._signatures
ASyncFunctionAsyncDocumenter.content_indent
ASyncFunctionAsyncDocumenter.documenters
ASyncFunctionAsyncDocumenter.member_order
ASyncFunctionAsyncDocumenter.objtype
ASyncFunctionAsyncDocumenter.option_spec
ASyncFunctionAsyncDocumenter.priority
ASyncFunctionAsyncDocumenter.titles_allowed
ASyncFunctionDirective
ASyncFunctionDirective.__init__()
ASyncFunctionDirective._object_hierarchy_parts()
ASyncFunctionDirective._toc_entry_name()
ASyncFunctionDirective.add_name()
ASyncFunctionDirective.add_target_and_index()
ASyncFunctionDirective.after_content()
ASyncFunctionDirective.assert_has_content()
ASyncFunctionDirective.before_content()
ASyncFunctionDirective.debug()
ASyncFunctionDirective.directive_error()
ASyncFunctionDirective.error()
ASyncFunctionDirective.get_field_type_map()
ASyncFunctionDirective.get_index_text()
ASyncFunctionDirective.get_location()
ASyncFunctionDirective.get_signature_prefix()
ASyncFunctionDirective.get_signatures()
ASyncFunctionDirective.get_source_info()
ASyncFunctionDirective.handle_signature()
ASyncFunctionDirective.info()
ASyncFunctionDirective.needs_arglist()
ASyncFunctionDirective.parse_content_to_nodes()
ASyncFunctionDirective.parse_inline()
ASyncFunctionDirective.parse_text_to_nodes()
ASyncFunctionDirective.run()
ASyncFunctionDirective.set_source_info()
ASyncFunctionDirective.severe()
ASyncFunctionDirective.transform_content()
ASyncFunctionDirective.warning()
ASyncFunctionDirective._doc_field_type_map
ASyncFunctionDirective.allow_nesting
ASyncFunctionDirective.config
ASyncFunctionDirective.doc_field_types
ASyncFunctionDirective.domain
ASyncFunctionDirective.env
ASyncFunctionDirective.final_argument_whitespace
ASyncFunctionDirective.has_content
ASyncFunctionDirective.indexnode
ASyncFunctionDirective.objtype
ASyncFunctionDirective.option_spec
ASyncFunctionDirective.optional_arguments
ASyncFunctionDirective.prefix_env
ASyncFunctionDirective.required_arguments
ASyncFunctionDocumenter
ASyncFunctionDocumenter.typ
ASyncFunctionDocumenter.__init__()
ASyncFunctionDocumenter._call_format_args()
ASyncFunctionDocumenter._find_signature()
ASyncFunctionDocumenter.add_content()
ASyncFunctionDocumenter.add_directive_header()
ASyncFunctionDocumenter.add_line()
ASyncFunctionDocumenter.annotate_to_first_argument()
ASyncFunctionDocumenter.can_document_member()
ASyncFunctionDocumenter.check_module()
ASyncFunctionDocumenter.document_members()
ASyncFunctionDocumenter.filter_members()
ASyncFunctionDocumenter.format_args()
ASyncFunctionDocumenter.format_name()
ASyncFunctionDocumenter.format_signature()
ASyncFunctionDocumenter.generate()
ASyncFunctionDocumenter.get_attr()
ASyncFunctionDocumenter.get_doc()
ASyncFunctionDocumenter.get_object_members()
ASyncFunctionDocumenter.get_real_modname()
ASyncFunctionDocumenter.get_sourcename()
ASyncFunctionDocumenter.import_object()
ASyncFunctionDocumenter.merge_default_value()
ASyncFunctionDocumenter.parse_name()
ASyncFunctionDocumenter.process_doc()
ASyncFunctionDocumenter.resolve_name()
ASyncFunctionDocumenter.sort_members()
ASyncFunctionDocumenter._new_docstrings
ASyncFunctionDocumenter._signatures
ASyncFunctionDocumenter.content_indent
ASyncFunctionDocumenter.documenters
ASyncFunctionDocumenter.member_order
ASyncFunctionDocumenter.objtype
ASyncFunctionDocumenter.option_spec
ASyncFunctionDocumenter.priority
ASyncFunctionDocumenter.titles_allowed
ASyncFunctionSyncDirective
ASyncFunctionSyncDirective.__init__()
ASyncFunctionSyncDirective._object_hierarchy_parts()
ASyncFunctionSyncDirective._toc_entry_name()
ASyncFunctionSyncDirective.add_name()
ASyncFunctionSyncDirective.add_target_and_index()
ASyncFunctionSyncDirective.after_content()
ASyncFunctionSyncDirective.assert_has_content()
ASyncFunctionSyncDirective.before_content()
ASyncFunctionSyncDirective.debug()
ASyncFunctionSyncDirective.directive_error()
ASyncFunctionSyncDirective.error()
ASyncFunctionSyncDirective.get_field_type_map()
ASyncFunctionSyncDirective.get_index_text()
ASyncFunctionSyncDirective.get_location()
ASyncFunctionSyncDirective.get_signature_prefix()
ASyncFunctionSyncDirective.get_signatures()
ASyncFunctionSyncDirective.get_source_info()
ASyncFunctionSyncDirective.handle_signature()
ASyncFunctionSyncDirective.info()
ASyncFunctionSyncDirective.needs_arglist()
ASyncFunctionSyncDirective.parse_content_to_nodes()
ASyncFunctionSyncDirective.parse_inline()
ASyncFunctionSyncDirective.parse_text_to_nodes()
ASyncFunctionSyncDirective.run()
ASyncFunctionSyncDirective.set_source_info()
ASyncFunctionSyncDirective.severe()
ASyncFunctionSyncDirective.transform_content()
ASyncFunctionSyncDirective.warning()
ASyncFunctionSyncDirective._doc_field_type_map
ASyncFunctionSyncDirective.allow_nesting
ASyncFunctionSyncDirective.config
ASyncFunctionSyncDirective.doc_field_types
ASyncFunctionSyncDirective.domain
ASyncFunctionSyncDirective.env
ASyncFunctionSyncDirective.final_argument_whitespace
ASyncFunctionSyncDirective.has_content
ASyncFunctionSyncDirective.indexnode
ASyncFunctionSyncDirective.objtype
ASyncFunctionSyncDirective.option_spec
ASyncFunctionSyncDirective.optional_arguments
ASyncFunctionSyncDirective.prefix_env
ASyncFunctionSyncDirective.required_arguments
ASyncFunctionSyncDocumenter
ASyncFunctionSyncDocumenter.typ
ASyncFunctionSyncDocumenter.__init__()
ASyncFunctionSyncDocumenter._call_format_args()
ASyncFunctionSyncDocumenter._find_signature()
ASyncFunctionSyncDocumenter.add_content()
ASyncFunctionSyncDocumenter.add_directive_header()
ASyncFunctionSyncDocumenter.add_line()
ASyncFunctionSyncDocumenter.annotate_to_first_argument()
ASyncFunctionSyncDocumenter.can_document_member()
ASyncFunctionSyncDocumenter.check_module()
ASyncFunctionSyncDocumenter.document_members()
ASyncFunctionSyncDocumenter.filter_members()
ASyncFunctionSyncDocumenter.format_args()
ASyncFunctionSyncDocumenter.format_name()
ASyncFunctionSyncDocumenter.format_signature()
ASyncFunctionSyncDocumenter.generate()
ASyncFunctionSyncDocumenter.get_attr()
ASyncFunctionSyncDocumenter.get_doc()
ASyncFunctionSyncDocumenter.get_object_members()
ASyncFunctionSyncDocumenter.get_real_modname()
ASyncFunctionSyncDocumenter.get_sourcename()
ASyncFunctionSyncDocumenter.import_object()
ASyncFunctionSyncDocumenter.merge_default_value()
ASyncFunctionSyncDocumenter.parse_name()
ASyncFunctionSyncDocumenter.process_doc()
ASyncFunctionSyncDocumenter.resolve_name()
ASyncFunctionSyncDocumenter.sort_members()
ASyncFunctionSyncDocumenter._new_docstrings
ASyncFunctionSyncDocumenter._signatures
ASyncFunctionSyncDocumenter.content_indent
ASyncFunctionSyncDocumenter.documenters
ASyncFunctionSyncDocumenter.member_order
ASyncFunctionSyncDocumenter.objtype
ASyncFunctionSyncDocumenter.option_spec
ASyncFunctionSyncDocumenter.priority
ASyncFunctionSyncDocumenter.titles_allowed
ASyncGeneratorFunctionDirective
ASyncGeneratorFunctionDirective.__init__()
ASyncGeneratorFunctionDirective._object_hierarchy_parts()
ASyncGeneratorFunctionDirective._toc_entry_name()
ASyncGeneratorFunctionDirective.add_name()
ASyncGeneratorFunctionDirective.add_target_and_index()
ASyncGeneratorFunctionDirective.after_content()
ASyncGeneratorFunctionDirective.assert_has_content()
ASyncGeneratorFunctionDirective.before_content()
ASyncGeneratorFunctionDirective.debug()
ASyncGeneratorFunctionDirective.directive_error()
ASyncGeneratorFunctionDirective.error()
ASyncGeneratorFunctionDirective.get_field_type_map()
ASyncGeneratorFunctionDirective.get_index_text()
ASyncGeneratorFunctionDirective.get_location()
ASyncGeneratorFunctionDirective.get_signature_prefix()
ASyncGeneratorFunctionDirective.get_signatures()
ASyncGeneratorFunctionDirective.get_source_info()
ASyncGeneratorFunctionDirective.handle_signature()
ASyncGeneratorFunctionDirective.info()
ASyncGeneratorFunctionDirective.needs_arglist()
ASyncGeneratorFunctionDirective.parse_content_to_nodes()
ASyncGeneratorFunctionDirective.parse_inline()
ASyncGeneratorFunctionDirective.parse_text_to_nodes()
ASyncGeneratorFunctionDirective.run()
ASyncGeneratorFunctionDirective.set_source_info()
ASyncGeneratorFunctionDirective.severe()
ASyncGeneratorFunctionDirective.transform_content()
ASyncGeneratorFunctionDirective.warning()
ASyncGeneratorFunctionDirective._doc_field_type_map
ASyncGeneratorFunctionDirective.allow_nesting
ASyncGeneratorFunctionDirective.config
ASyncGeneratorFunctionDirective.doc_field_types
ASyncGeneratorFunctionDirective.domain
ASyncGeneratorFunctionDirective.env
ASyncGeneratorFunctionDirective.final_argument_whitespace
ASyncGeneratorFunctionDirective.has_content
ASyncGeneratorFunctionDirective.indexnode
ASyncGeneratorFunctionDirective.objtype
ASyncGeneratorFunctionDirective.option_spec
ASyncGeneratorFunctionDirective.optional_arguments
ASyncGeneratorFunctionDirective.prefix_env
ASyncGeneratorFunctionDirective.required_arguments
ASyncGeneratorFunctionDocumenter
ASyncGeneratorFunctionDocumenter.typ
ASyncGeneratorFunctionDocumenter.__init__()
ASyncGeneratorFunctionDocumenter._call_format_args()
ASyncGeneratorFunctionDocumenter._find_signature()
ASyncGeneratorFunctionDocumenter.add_content()
ASyncGeneratorFunctionDocumenter.add_directive_header()
ASyncGeneratorFunctionDocumenter.add_line()
ASyncGeneratorFunctionDocumenter.annotate_to_first_argument()
ASyncGeneratorFunctionDocumenter.can_document_member()
ASyncGeneratorFunctionDocumenter.check_module()
ASyncGeneratorFunctionDocumenter.document_members()
ASyncGeneratorFunctionDocumenter.filter_members()
ASyncGeneratorFunctionDocumenter.format_args()
ASyncGeneratorFunctionDocumenter.format_name()
ASyncGeneratorFunctionDocumenter.format_signature()
ASyncGeneratorFunctionDocumenter.generate()
ASyncGeneratorFunctionDocumenter.get_attr()
ASyncGeneratorFunctionDocumenter.get_doc()
ASyncGeneratorFunctionDocumenter.get_object_members()
ASyncGeneratorFunctionDocumenter.get_real_modname()
ASyncGeneratorFunctionDocumenter.get_sourcename()
ASyncGeneratorFunctionDocumenter.import_object()
ASyncGeneratorFunctionDocumenter.merge_default_value()
ASyncGeneratorFunctionDocumenter.parse_name()
ASyncGeneratorFunctionDocumenter.process_doc()
ASyncGeneratorFunctionDocumenter.resolve_name()
ASyncGeneratorFunctionDocumenter.sort_members()
ASyncGeneratorFunctionDocumenter._new_docstrings
ASyncGeneratorFunctionDocumenter._signatures
ASyncGeneratorFunctionDocumenter.content_indent
ASyncGeneratorFunctionDocumenter.documenters
ASyncGeneratorFunctionDocumenter.member_order
ASyncGeneratorFunctionDocumenter.objtype
ASyncGeneratorFunctionDocumenter.option_spec
ASyncGeneratorFunctionDocumenter.priority
ASyncGeneratorFunctionDocumenter.titles_allowed
_ASyncDirective
_ASyncFunctionDirective
_ASyncFunctionDirective.__init__()
_ASyncFunctionDirective._object_hierarchy_parts()
_ASyncFunctionDirective._toc_entry_name()
_ASyncFunctionDirective.add_name()
_ASyncFunctionDirective.add_target_and_index()
_ASyncFunctionDirective.after_content()
_ASyncFunctionDirective.assert_has_content()
_ASyncFunctionDirective.before_content()
_ASyncFunctionDirective.debug()
_ASyncFunctionDirective.directive_error()
_ASyncFunctionDirective.error()
_ASyncFunctionDirective.get_field_type_map()
_ASyncFunctionDirective.get_index_text()
_ASyncFunctionDirective.get_location()
_ASyncFunctionDirective.get_signature_prefix()
_ASyncFunctionDirective.get_signatures()
_ASyncFunctionDirective.get_source_info()
_ASyncFunctionDirective.handle_signature()
_ASyncFunctionDirective.info()
_ASyncFunctionDirective.needs_arglist()
_ASyncFunctionDirective.parse_content_to_nodes()
_ASyncFunctionDirective.parse_inline()
_ASyncFunctionDirective.parse_text_to_nodes()
_ASyncFunctionDirective.run()
_ASyncFunctionDirective.set_source_info()
_ASyncFunctionDirective.severe()
_ASyncFunctionDirective.transform_content()
_ASyncFunctionDirective.warning()
_ASyncFunctionDirective._doc_field_type_map
_ASyncFunctionDirective.allow_nesting
_ASyncFunctionDirective.config
_ASyncFunctionDirective.doc_field_types
_ASyncFunctionDirective.domain
_ASyncFunctionDirective.env
_ASyncFunctionDirective.final_argument_whitespace
_ASyncFunctionDirective.has_content
_ASyncFunctionDirective.indexnode
_ASyncFunctionDirective.objtype
_ASyncFunctionDirective.option_spec
_ASyncFunctionDirective.optional_arguments
_ASyncFunctionDirective.prefix_env
_ASyncFunctionDirective.required_arguments
_ASyncFunctionDocumenter
_ASyncFunctionDocumenter.__init__()
_ASyncFunctionDocumenter._call_format_args()
_ASyncFunctionDocumenter._find_signature()
_ASyncFunctionDocumenter.add_content()
_ASyncFunctionDocumenter.add_directive_header()
_ASyncFunctionDocumenter.add_line()
_ASyncFunctionDocumenter.annotate_to_first_argument()
_ASyncFunctionDocumenter.can_document_member()
_ASyncFunctionDocumenter.check_module()
_ASyncFunctionDocumenter.document_members()
_ASyncFunctionDocumenter.filter_members()
_ASyncFunctionDocumenter.format_args()
_ASyncFunctionDocumenter.format_name()
_ASyncFunctionDocumenter.format_signature()
_ASyncFunctionDocumenter.generate()
_ASyncFunctionDocumenter.get_attr()
_ASyncFunctionDocumenter.get_doc()
_ASyncFunctionDocumenter.get_object_members()
_ASyncFunctionDocumenter.get_real_modname()
_ASyncFunctionDocumenter.get_sourcename()
_ASyncFunctionDocumenter.import_object()
_ASyncFunctionDocumenter.merge_default_value()
_ASyncFunctionDocumenter.parse_name()
_ASyncFunctionDocumenter.process_doc()
_ASyncFunctionDocumenter.resolve_name()
_ASyncFunctionDocumenter.sort_members()
_ASyncFunctionDocumenter._new_docstrings
_ASyncFunctionDocumenter._signatures
_ASyncFunctionDocumenter.content_indent
_ASyncFunctionDocumenter.documenters
_ASyncFunctionDocumenter.member_order
_ASyncFunctionDocumenter.objtype
_ASyncFunctionDocumenter.option_spec
_ASyncFunctionDocumenter.priority
_ASyncFunctionDocumenter.titles_allowed
_ASyncFunctionDocumenter.typ
_ASyncMethodDirective
_ASyncMethodDirective.__init__()
_ASyncMethodDirective._object_hierarchy_parts()
_ASyncMethodDirective._toc_entry_name()
_ASyncMethodDirective.add_name()
_ASyncMethodDirective.add_target_and_index()
_ASyncMethodDirective.after_content()
_ASyncMethodDirective.assert_has_content()
_ASyncMethodDirective.before_content()
_ASyncMethodDirective.debug()
_ASyncMethodDirective.directive_error()
_ASyncMethodDirective.error()
_ASyncMethodDirective.get_field_type_map()
_ASyncMethodDirective.get_index_text()
_ASyncMethodDirective.get_location()
_ASyncMethodDirective.get_signature_prefix()
_ASyncMethodDirective.get_signatures()
_ASyncMethodDirective.get_source_info()
_ASyncMethodDirective.handle_signature()
_ASyncMethodDirective.info()
_ASyncMethodDirective.needs_arglist()
_ASyncMethodDirective.parse_content_to_nodes()
_ASyncMethodDirective.parse_inline()
_ASyncMethodDirective.parse_text_to_nodes()
_ASyncMethodDirective.run()
_ASyncMethodDirective.set_source_info()
_ASyncMethodDirective.severe()
_ASyncMethodDirective.transform_content()
_ASyncMethodDirective.warning()
_ASyncMethodDirective._doc_field_type_map
_ASyncMethodDirective.allow_nesting
_ASyncMethodDirective.config
_ASyncMethodDirective.doc_field_types
_ASyncMethodDirective.domain
_ASyncMethodDirective.env
_ASyncMethodDirective.final_argument_whitespace
_ASyncMethodDirective.has_content
_ASyncMethodDirective.indexnode
_ASyncMethodDirective.objtype
_ASyncMethodDirective.option_spec
_ASyncMethodDirective.optional_arguments
_ASyncMethodDirective.prefix_env
_ASyncMethodDirective.required_arguments
_ASyncMethodDocumenter
_ASyncMethodDocumenter.__init__()
_ASyncMethodDocumenter._call_format_args()
_ASyncMethodDocumenter._find_signature()
_ASyncMethodDocumenter.add_content()
_ASyncMethodDocumenter.add_directive_header()
_ASyncMethodDocumenter.add_line()
_ASyncMethodDocumenter.annotate_to_first_argument()
_ASyncMethodDocumenter.can_document_member()
_ASyncMethodDocumenter.check_module()
_ASyncMethodDocumenter.document_members()
_ASyncMethodDocumenter.filter_members()
_ASyncMethodDocumenter.format_args()
_ASyncMethodDocumenter.format_name()
_ASyncMethodDocumenter.format_signature()
_ASyncMethodDocumenter.generate()
_ASyncMethodDocumenter.get_attr()
_ASyncMethodDocumenter.get_doc()
_ASyncMethodDocumenter.get_object_members()
_ASyncMethodDocumenter.get_real_modname()
_ASyncMethodDocumenter.get_sourcename()
_ASyncMethodDocumenter.import_object()
_ASyncMethodDocumenter.merge_default_value()
_ASyncMethodDocumenter.parse_name()
_ASyncMethodDocumenter.process_doc()
_ASyncMethodDocumenter.resolve_name()
_ASyncMethodDocumenter.sort_members()
_ASyncMethodDocumenter._new_docstrings
_ASyncMethodDocumenter._signatures
_ASyncMethodDocumenter.content_indent
_ASyncMethodDocumenter.directivetype
_ASyncMethodDocumenter.documenters
_ASyncMethodDocumenter.member_order
_ASyncMethodDocumenter.objtype
_ASyncMethodDocumenter.option_spec
_ASyncMethodDocumenter.priority
_ASyncMethodDocumenter.titles_allowed
_ASyncMethodDocumenter.typ
_ASyncWrapperDocumenter
autodoc_skip_member_handler()
setup()
- Module contents
- a_sync.utils package
Submodules
a_sync.ENVIRONMENT_VARIABLES module
- a_sync.ENVIRONMENT_VARIABLES.DEBUG_CLASS_NAME = <EnvironmentVariable[name=`EZASYNC_DEBUG_CLASS_NAME`, type=str, default_value=, current_value=, using_default=True]>
The name of the class to debug.
If you’re only interested in debugging a specific class, set this to the class name.
Examples
To debug a class named MyClass, set the environment variable:
export EZASYNC_DEBUG_CLASS_NAME=MyClass
See also
DEBUG_MODE()
for enabling debug mode on all classes.- Type:
- a_sync.ENVIRONMENT_VARIABLES.DEBUG_MODE = <EnvironmentVariable[name=`EZASYNC_DEBUG_MODE`, type=bool, default_value=False, current_value=False, using_default=True]>
Enables debug mode on all classes.
Set this environment variable to True to enable debug mode on all classes. If DEBUG_CLASS_NAME is set to a non-empty string, DEBUG_MODE will default to True.
Examples
To enable debug mode globally, set the environment variable:
export EZASYNC_DEBUG_MODE=True
If you have set DEBUG_CLASS_NAME to a specific class, DEBUG_MODE will automatically be True unless DEBUG_CLASS_NAME is an empty string.
See also
DEBUG_CLASS_NAME()
for debugging a specific class.- Type:
a_sync._smart module
This module defines smart future and task utilities for the a_sync library.
These utilities provide enhanced functionality for managing asynchronous tasks and futures,
including a custom task factory for creating SmartTask
instances and a shielding mechanism
to protect tasks from cancellation.
- class a_sync._smart.SmartFuture[source]
Bases:
_SmartFutureMixin
[T
],Future
A smart future that tracks waiters and integrates with a smart processing queue.
Inherits from both
_SmartFutureMixin
andasyncio.Future
, providing additional functionality for tracking waiters and integrating with a smart processing queue.Example
Creating and awaiting a SmartFuture:
`python future = SmartFuture() await future `
See also
_SmartFutureMixin
- __init__(*, queue, key=None, loop=None)[source]
Initialize the SmartFuture with an optional queue and key.
- Parameters:
- Return type:
None
Example
`python future = SmartFuture(queue=my_queue, key=my_key) `
See also
SmartProcessingQueue
- __iter__()
Implement iter(self).
- _make_cancelled_error()
Create the CancelledError to raise if the Future is cancelled.
This should only be called once when handling a cancellation since it erases the context exception value.
- _repr_info()
- _self_done_cleanup_callback()
Callback to clean up waiters and remove the future from the queue when done.
This method clears all waiters and removes the future from the associated queue.
- Parameters:
self (SmartFuture | SmartTask)
- Return type:
None
- _waiter_done_cleanup_callback(waiter)
Callback to clean up waiters when a waiter task is done.
Removes the waiter from _waiters, and _queue._futs if applicable.
- Parameters:
waiter (SmartTask) – The waiter task to clean up.
self (SmartFuture | SmartTask)
- Return type:
None
Example
Automatically called when a waiter task completes.
- add_done_callback()
Add a callback to be run when the future becomes done.
The callback is called with a single argument - the future object. If the future is already done when this is called, the callback is scheduled with call_soon.
- cancel(msg=None)
Cancel the future and schedule callbacks.
If the future is already done or cancelled, return False. Otherwise, change the future’s state to cancelled, schedule the callbacks and return True.
- cancelled()
Return True if the future was cancelled.
- done()
Return True if the future is done.
Done means either that a result / exception are available, or that the future was cancelled.
- exception()
Return the exception that was set on this future.
The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn’t done yet, raises InvalidStateError.
- get_loop()
Return the event loop the Future is bound to.
- remove_done_callback(fn, /)
Remove all instances of a callback from the “call when done” list.
Returns the number of callbacks removed.
- result()
Return the result this future represents.
If the future has been cancelled, raises CancelledError. If the future’s result isn’t yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised.
- set_exception(exception, /)
Mark the future done and set an exception.
If the future is already done when this method is called, raises InvalidStateError.
- set_result(result, /)
Mark the future done and set its result.
If the future is already done when this method is called, raises InvalidStateError.
- _asyncio_future_blocking
- _callbacks
- _cancel_message
- _exception
- _key: _Key = None
- _log_traceback
- _loop
- _result
- _source_traceback
- _state
- _waiters: weakref.WeakSet[SmartTask[T]]
- class a_sync._smart.SmartTask[source]
Bases:
_SmartFutureMixin
[T
],Task
A smart task that tracks waiters and integrates with a smart processing queue.
Inherits from both
_SmartFutureMixin
andasyncio.Task
, providing additional functionality for tracking waiters and integrating with a smart processing queue.Example
Creating and awaiting a SmartTask:
`python task = SmartTask(coro=my_coroutine()) await task `
See also
_SmartFutureMixin
- __init__(coro, *, loop=None, name=None)[source]
Initialize the SmartTask with a coroutine and optional event loop.
- Parameters:
- Return type:
None
Example
`python task = SmartTask(coro=my_coroutine(), name="my_task") `
See also
- __iter__()
Implement iter(self).
- _make_cancelled_error()
Create the CancelledError to raise if the Task is cancelled.
This should only be called once when handling a cancellation since it erases the context exception value.
- _repr_info()
- _self_done_cleanup_callback()
Callback to clean up waiters and remove the future from the queue when done.
This method clears all waiters and removes the future from the associated queue.
- Parameters:
self (SmartFuture | SmartTask)
- Return type:
None
- _waiter_done_cleanup_callback(waiter)
Callback to clean up waiters when a waiter task is done.
Removes the waiter from _waiters, and _queue._futs if applicable.
- Parameters:
waiter (SmartTask) – The waiter task to clean up.
self (SmartFuture | SmartTask)
- Return type:
None
Example
Automatically called when a waiter task completes.
- add_done_callback()
Add a callback to be run when the future becomes done.
The callback is called with a single argument - the future object. If the future is already done when this is called, the callback is scheduled with call_soon.
- cancel(msg=None)
Request that this task cancel itself.
This arranges for a CancelledError to be thrown into the wrapped coroutine on the next cycle through the event loop. The coroutine then has a chance to clean up or even deny the request using try/except/finally.
Unlike Future.cancel, this does not guarantee that the task will be cancelled: the exception might be caught and acted upon, delaying cancellation of the task or preventing cancellation completely. The task may also return a value or raise a different exception.
Immediately after this method is called, Task.cancelled() will not return True (unless the task was already cancelled). A task will be marked as cancelled when the wrapped coroutine terminates with a CancelledError exception (even if cancel() was not called).
- cancelled()
Return True if the future was cancelled.
- done()
Return True if the future is done.
Done means either that a result / exception are available, or that the future was cancelled.
- exception()
Return the exception that was set on this future.
The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn’t done yet, raises InvalidStateError.
- get_coro()
- get_loop()
Return the event loop the Future is bound to.
- get_name()
- get_stack(*, limit=None)
Return the list of stack frames for this task’s coroutine.
If the coroutine is not done, this returns the stack where it is suspended. If the coroutine has completed successfully or was cancelled, this returns an empty list. If the coroutine was terminated by an exception, this returns the list of traceback frames.
The frames are always ordered from oldest to newest.
The optional limit gives the maximum number of frames to return; by default all available frames are returned. Its meaning differs depending on whether a stack or a traceback is returned: the newest frames of a stack are returned, but the oldest frames of a traceback are returned. (This matches the behavior of the traceback module.)
For reasons beyond our control, only one stack frame is returned for a suspended coroutine.
- print_stack(*, limit=None, file=None)
Print the stack or traceback for this task’s coroutine.
This produces output similar to that of the traceback module, for the frames retrieved by get_stack(). The limit argument is passed to get_stack(). The file argument is an I/O stream to which the output is written; by default output is written to sys.stderr.
- remove_done_callback(fn, /)
Remove all instances of a callback from the “call when done” list.
Returns the number of callbacks removed.
- result()
Return the result this future represents.
If the future has been cancelled, raises CancelledError. If the future’s result isn’t yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised.
- set_exception(exception, /)
Mark the future done and set an exception.
If the future is already done when this method is called, raises InvalidStateError.
- set_name(value, /)
- set_result(result, /)
Mark the future done and set its result.
If the future is already done when this method is called, raises InvalidStateError.
- _asyncio_future_blocking
- _callbacks
- _cancel_message
- _coro
- _exception
- _fut_waiter
- _key: _Key
- _log_destroy_pending
- _log_traceback
- _loop
- _must_cancel
- _result
- _source_traceback
- _state
- _waiters: Set['asyncio.Task[T]']
- a_sync._smart.create_future(*, queue=None, key=None, loop=None)[source]
Create a
SmartFuture
instance.- Parameters:
- Returns:
A SmartFuture instance.
- Return type:
SmartFuture[V]
Example
Creating a SmartFuture using the factory function:
`python future = create_future(queue=my_queue, key=my_key) `
See also
- a_sync._smart.set_smart_task_factory(loop=None)[source]
Set the event loop’s task factory to
smart_task_factory()
so all tasks will be SmartTask instances.- Parameters:
loop (AbstractEventLoop | None) – Optional; the event loop. If None, the current event loop is used.
- Return type:
None
Example
Setting the smart task factory for the current event loop:
`python set_smart_task_factory() `
See also
- a_sync._smart.shield(arg, *, loop=None)[source]
Wait for a future, shielding it from cancellation.
The statement
res = await shield(something())
is exactly equivalent to the statement
res = await something()
except that if the coroutine containing it is cancelled, the task running in something() is not cancelled. From the POV of something(), the cancellation did not happen. But its caller is still cancelled, so the yield-from expression still raises CancelledError. Note: If something() is cancelled by other means this will still cancel shield().
If you want to completely ignore cancellation (not recommended) you can combine shield() with a try/except clause, as follows:
- try:
res = await shield(something())
- except CancelledError:
res = None
- Parameters:
arg (Awaitable[T]) – The awaitable to shield from cancellation.
loop (AbstractEventLoop | None) – Optional; the event loop. Deprecated since Python 3.8.
- Returns:
A
SmartFuture
orasyncio.Future
instance.- Return type:
SmartFuture[T] | Future
Example
Using shield to protect a coroutine from cancellation:
`python result = await shield(my_coroutine()) `
See also
- a_sync._smart.smart_task_factory(loop, coro)[source]
Task factory function that an event loop calls to create new tasks.
This factory function utilizes ez-a-sync’s custom
SmartTask
implementation.- Parameters:
loop (AbstractEventLoop) – The event loop.
coro (Awaitable[T]) – The coroutine to run in the task.
- Returns:
A SmartTask instance running the provided coroutine.
- Return type:
SmartTask[T]
Example
Using the smart task factory to create a SmartTask:
`python loop = asyncio.get_event_loop() task = smart_task_factory(loop, my_coroutine()) `
See also
a_sync._typing module
This module provides type definitions and type-related utilities for the a_sync library.
It includes various type aliases and protocols used throughout the library to enhance type checking and provide better IDE support.
Examples
The following examples demonstrate how to use some of the type aliases and protocols defined in this module.
Example of a function that can return either an awaitable or a direct value:
```python from a_sync._typing import MaybeAwaitable from typing import Awaitable
- async def process_data(data: MaybeAwaitable[int]) -> int:
- if isinstance(data, Awaitable):
return await data
return data
# Usage import asyncio
- async def main():
result = await process_data(asyncio.sleep(1, result=42)) print(result) # Output: 42
result = await process_data(42) print(result) # Output: 42
Example of defining a coroutine function type using CoroFn with ParamSpec:
```python from a_sync._typing import CoroFn from typing_extensions import ParamSpec from typing import Awaitable
P = ParamSpec(“P”)
- async def async_function(x: int) -> str:
return str(x)
coro_fn: CoroFn[[int], str] = async_function ```
Example of defining a synchronous function type using SyncFn with ParamSpec:
```python from a_sync._typing import SyncFn from typing_extensions import ParamSpec
P = ParamSpec(“P”)
- def sync_function(x: int) -> str:
return str(x)
sync_fn: SyncFn[[int], str] = sync_function ```
- class a_sync._typing.AsyncUnboundMethod[source]
-
Protocol for unbound asynchronous methods.
An unbound method is a method that hasn’t been bound to an instance of a class yet. It’s essentially the function object itself, before it’s accessed through an instance.
- __init__(*args, **kwargs)
- class a_sync._typing.CoroBoundMethod[source]
-
Protocol for coroutine bound methods.
Example
- class MyClass:
- async def my_method(self, x: int) -> str:
return str(x)
instance = MyClass() bound_method: CoroBoundMethod[MyClass, [int], str] = instance.my_method
- __init__(*args, **kwargs)
- class a_sync._typing.I
A
TypeVar
that is used to represent instances of a common class.alias of TypeVar(‘I’)
- __init__(name, *constraints, bound=None, covariant=False, contravariant=False)
- class a_sync._typing.ModifierKwargs[source]
Bases:
TypedDict
TypedDict for keyword arguments that modify the behavior of asynchronous operations.
- __getitem__()
x.__getitem__(y) <==> x[y]
- __init__(*args, **kwargs)
- __iter__()
Implement iter(self).
- clear() None. Remove all items from D.
- copy() a shallow copy of D
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values
- executor: Executor
- class a_sync._typing.SyncBoundMethod[source]
-
Protocol for synchronous bound methods.
Example
- class MyClass:
- def my_method(self, x: int) -> str:
return str(x)
instance = MyClass() bound_method: SyncBoundMethod[MyClass, [int], str] = instance.my_method
- __init__(*args, **kwargs)
- class a_sync._typing.SyncUnboundMethod[source]
-
Protocol for unbound synchronous methods.
An unbound method is a method that hasn’t been bound to an instance of a class yet. It’s essentially the function object itself, before it’s accessed through an instance.
- __init__(*args, **kwargs)
- a_sync._typing.AnyBoundMethod
Type alias for any bound method, whether synchronous or asynchronous.
alias of
CoroBoundMethod
[Any
,P
,T
] |SyncBoundMethod
[Any
,P
,T
]
- a_sync._typing.AnyFn
Type alias for any function, whether synchronous or asynchronous.
- a_sync._typing.AnyGetterFunction
Type alias for any getter function, whether synchronous or asynchronous.
- a_sync._typing.AnyIterable
Type alias for any iterable, whether synchronous or asynchronous.
alias of
AsyncIterable
[K
] |Iterable
[K
]
- a_sync._typing.AnyIterableOrAwaitableIterable
Type alias for any iterable, whether synchronous or asynchronous, or an awaitable that resolves to any iterable, whether synchronous or asynchronous.
alias of
AsyncIterable
[K
] |Iterable
[K
] |Awaitable
[AsyncIterable
[K
] |Iterable
[K
]]
- a_sync._typing.AnyUnboundMethod
Type alias for any unbound method, whether synchronous or asynchronous.
alias of
AsyncUnboundMethod
[I
,P
,T
] |SyncUnboundMethod
[I
,P
,T
]
- a_sync._typing.AsyncDecorator
Type alias for decorators for coroutine functions.
alias of
Callable
[[Callable
[[P
],Awaitable
[T
]]],Callable
[[P
],Awaitable
[T
]]]
- a_sync._typing.AsyncDecoratorOrCoroFn
Type alias for either an asynchronous decorator or a coroutine function.
alias of
Callable
[[Callable
[[P
],Awaitable
[T
]]],Callable
[[P
],Awaitable
[T
]]] |Callable
[[P
],Awaitable
[T
]]
- a_sync._typing.AsyncGetterFunction
Type alias for asynchronous getter functions.
- a_sync._typing.CoroFn
Type alias for any function that returns an awaitable.
- a_sync._typing.DefaultMode
Type alias for default modes of operation.
alias of
Literal
[‘sync’, ‘async’, None]
- a_sync._typing.MaybeAwaitable
Type alias for values that may or may not be awaitable. Useful for functions that can return either an awaitable or a direct value.
alias of
Awaitable
[T
] |T
- a_sync._typing.MaybeCoro
Type alias for values that may or may not be coroutine.
- a_sync._typing.Numeric
Type alias for numeric values of types int, float, or Decimal.
- a_sync._typing.P = ~P
A
ParamSpec
used everywhere in the lib.
- a_sync._typing.SemaphoreSpec
Type alias for semaphore specifications.
a_sync.aliases module
a_sync.exceptions module
This module defines custom exceptions for the a_sync library.
- exception a_sync.exceptions.ASyncFlagException[source]
Bases:
ValueError
Base exception class for flag-related errors in the a_sync library.
A-Sync uses ‘flags’ to indicate whether objects or function calls will be sync or async. You can use any of the provided flags, which include ‘sync’ and ‘asynchronous’, whichever makes most sense for your use case.
Examples
>>> try: ... raise ASyncFlagException("An error occurred with flags.") ... except ASyncFlagException as e: ... print(e) An error occurred with flags.
See also
VIABLE_FLAGS
- desc(target)[source]
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
- exception a_sync.exceptions.ASyncRuntimeError[source]
Bases:
RuntimeError
Raised for runtime errors in asynchronous operations.
Examples
>>> try: ... raise ASyncRuntimeError(RuntimeError("Some runtime error")) ... except ASyncRuntimeError as e: ... print(e) Some runtime error
- __init__(e)[source]
Initializes the ASyncRuntimeError exception.
- Parameters:
e (RuntimeError) – The original runtime error.
See also
- exception a_sync.exceptions.EmptySequenceError[source]
Bases:
ValueError
Raised when an operation is attempted on an empty sequence but items are required.
Examples
>>> try: ... raise EmptySequenceError("Sequence is empty") ... except EmptySequenceError as e: ... print(e) Sequence is empty
- exception a_sync.exceptions.FlagNotDefined[source]
Bases:
ASyncFlagException
Raised when a flag is not defined on an object.
Examples
>>> class SomeClass: ... pass ... >>> try: ... raise FlagNotDefined(SomeClass, "some_flag") ... except FlagNotDefined as e: ... print(e) <class '__main__.SomeClass'> flag some_flag is not defined.
- desc(target)
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
- exception a_sync.exceptions.FunctionNotAsync[source]
Bases:
ImproperFunctionType
Raised when a function expected to be async is not.
Examples
>>> def some_function(): ... pass ... >>> try: ... raise FunctionNotAsync(some_function) ... except FunctionNotAsync as e: ... print(e) `coro_fn` must be a coroutine function defined with `async def`. You passed <function some_function at 0x...>.
- exception a_sync.exceptions.FunctionNotSync[source]
Bases:
ImproperFunctionType
Raised when a function expected to be sync is actually async.
Examples
>>> async def some_async_function(): ... pass ... >>> try: ... raise FunctionNotSync(some_async_function) ... except FunctionNotSync as e: ... print(e) `func` must be a coroutine function defined with `def`. You passed <function some_async_function at 0x...>.
- exception a_sync.exceptions.ImproperFunctionType[source]
Bases:
ValueError
Raised when a function that should be sync is async or vice-versa.
See also
- exception a_sync.exceptions.InvalidFlag[source]
Bases:
ASyncFlagException
Raised when an invalid flag is encountered.
Examples
>>> try: ... raise InvalidFlag("invalid_flag") ... except InvalidFlag as e: ... print(e) 'flag' must be one of: {'sync', 'asynchronous'}. You passed invalid_flag. This code should not be reached and likely indicates an issue with a custom subclass definition.
See also
VIABLE_FLAGS
- __init__(flag)[source]
Initializes the InvalidFlag exception.
- Parameters:
flag (str | None) – The invalid flag.
See also
- desc(target)
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
- exception a_sync.exceptions.InvalidFlagValue[source]
Bases:
ASyncFlagException
Raised when a flag has an invalid value.
Examples
>>> try: ... raise InvalidFlagValue("some_flag", "not_a_boolean") ... except InvalidFlagValue as e: ... print(e) 'some_flag' should be boolean. You passed not_a_boolean.
- __init__(flag, flag_value)[source]
Initializes the InvalidFlagValue exception.
- Parameters:
See also
- desc(target)
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
- exception a_sync.exceptions.MappingError[source]
Bases:
Exception
Base class for errors related to
TaskMapping
.Examples
>>> from a_sync import TaskMapping >>> try: ... raise MappingError(TaskMapping(), "Some mapping error") ... except MappingError as e: ... print(e) Some mapping error: <TaskMapping object at 0x...> {}
- __init__(mapping, msg='')[source]
Initializes the MappingError exception.
- Parameters:
mapping (TaskMapping) – The TaskMapping where the error occurred.
msg (str) – An optional message describing the error.
See also
TaskMapping
- exception a_sync.exceptions.MappingIsEmptyError[source]
Bases:
MappingError
Raised when a TaskMapping is empty and an operation requires it to have items.
Examples
>>> from a_sync import TaskMapping >>> try: ... raise MappingIsEmptyError(TaskMapping()) ... except MappingIsEmptyError as e: ... print(e) TaskMapping does not contain anything to yield: <TaskMapping object at 0x...> {}
- __init__(mapping, msg='')
Initializes the MappingError exception.
- Parameters:
mapping (TaskMapping) – The TaskMapping where the error occurred.
msg (str) – An optional message describing the error.
See also
TaskMapping
- exception a_sync.exceptions.MappingNotEmptyError[source]
Bases:
MappingError
Raised when a TaskMapping is not empty and an operation requires it to be empty.
Examples
>>> from a_sync import TaskMapping >>> task_mapping = TaskMapping() >>> task_mapping['key'] = 'value' >>> try: ... raise MappingNotEmptyError(task_mapping) ... except MappingNotEmptyError as e: ... print(e) TaskMapping already contains some data. In order to use `map`, you need a fresh one: <TaskMapping object at 0x...> {'key': 'value'}
- __init__(mapping, msg='')
Initializes the MappingError exception.
- Parameters:
mapping (TaskMapping) – The TaskMapping where the error occurred.
msg (str) – An optional message describing the error.
See also
TaskMapping
- exception a_sync.exceptions.NoFlagsFound[source]
Bases:
ASyncFlagException
Raised when no viable flags are found in the target.
Examples
>>> try: ... raise NoFlagsFound("some_target") ... except NoFlagsFound as e: ... print(e) There are no viable a_sync flag attributes defined on some_target: Viable flags: {'sync', 'asynchronous'} This is likely an issue with a custom subclass definition.
- __init__(target, kwargs_keys=None)[source]
Initializes the NoFlagsFound exception.
- Parameters:
target – The target object where flags were expected.
kwargs_keys – Optional; keys in the kwargs if applicable.
- desc(target)
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
- exception a_sync.exceptions.PersistedTaskException[source]
Bases:
Exception
Raised when an exception persists in an asyncio Task.
Examples
>>> import asyncio >>> async def some_task(): ... raise ValueError("Some error") ... >>> task = asyncio.create_task(some_task()) >>> try: ... raise PersistedTaskException(ValueError("Some error"), task) ... except PersistedTaskException as e: ... print(e) ValueError: Some error
- exception a_sync.exceptions.SyncModeInAsyncContextError[source]
Bases:
ASyncRuntimeError
Raised when synchronous code is used within an asynchronous context.
Examples
>>> try: ... raise SyncModeInAsyncContextError() ... except SyncModeInAsyncContextError as e: ... print(e) The event loop is already running, which means you're trying to use an `ASyncFunction` synchronously from within an async context. Check your traceback to determine which, then try calling asynchronously instead with one of the following kwargs: {'sync', 'asynchronous'}
- exception a_sync.exceptions.TooManyFlags[source]
Bases:
ASyncFlagException
Raised when multiple flags are found, but only one was expected.
Examples
>>> try: ... raise TooManyFlags("some_target", ["flag1", "flag2"]) ... except TooManyFlags as e: ... print(e) There are multiple a_sync flag attributes defined on some_target and there should only be one. Present flags: ['flag1', 'flag2'] This is likely an issue with a custom subclass definition.
- __init__(target, present_flags)[source]
Initializes the TooManyFlags exception.
- Parameters:
target – The target object where flags were found.
present_flags – The flags that were found.
See also
- desc(target)
Returns a description of the target for the flag error message.
- Parameters:
target – The target object or string to describe.
- Return type:
Examples
>>> exception = ASyncFlagException() >>> exception.desc("kwargs") "flags present in 'kwargs'"
>>> exception.desc("some_target") 'flag attributes defined on some_target'
- viable_flags = {'asynchronous', 'sync'}
{‘sync’, ‘asynchronous’}.
- Type:
The set of viable flags
a_sync.executor module
This module provides several executor classes that facilitate running synchronous functions asynchronously using asyncio.
With these executors, you can run sync functions in your executor with await executor.run(fn, *args, **kwargs). The executor.submit(fn, *args, **kwargs) method works similarly to the concurrent.futures implementation but returns an asyncio.Future instead of a concurrent.futures.Future.
- Executor Classes:
AsyncProcessPoolExecutor
: A process pool executor providing asynchronous run and submit methods, with support for synchronous modeAsyncThreadPoolExecutor
: A thread pool executor providing asynchronous run and submit methods, with support for synchronous modePruningThreadPoolExecutor
: AnAsyncThreadPoolExecutor
that prunes inactive threads after a timeout, ensuring at least one thread remains active to prevent locks.
See also
concurrent.futures
for the original synchronous executor implementations.
- class a_sync.executor.AsyncProcessPoolExecutor[source]
Bases:
_AsyncExecutorMixin
,ProcessPoolExecutor
A :class:`concurrent.futures.ProcessPoolExecutor’ subclass providing asynchronous run and submit methods that support kwargs, with support for synchronous mode
Examples
>>> executor = AsyncProcessPoolExecutor(max_workers=4) >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, mp_context=None, initializer=None, initargs=())[source]
Initializes the AsyncProcessPoolExecutor.
- Parameters:
max_workers (int | None) – The maximum number of workers. Defaults to None.
mp_context (BaseContext | None) – The multiprocessing context. Defaults to None.
initializer (Callable[[...], object] | None) – An initializer callable. Defaults to None.
initargs (Tuple[Any, ...]) – Arguments for the initializer. Defaults to ().
- Return type:
None
Examples
>>> executor = AsyncProcessPoolExecutor(max_workers=4) >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_process_count()
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _launch_processes()
- _spawn_process()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _start_executor_manager_thread()
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – If greater than one, the iterables will be chopped into chunks of size chunksize and submitted to the process pool. If set to one, the items in the list will be sent one at a time.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _broken
- _call_queue
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _mp_context
- _pending_work_items
- _processes
- _queue_count
- _queue_management_thread
- _queue_management_thread_wakeup
- _result_queue
- _shutdown_lock
- _shutdown_thread
- _work_ids
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- class a_sync.executor.AsyncThreadPoolExecutor[source]
Bases:
_AsyncExecutorMixin
,ThreadPoolExecutor
A :class:`concurrent.futures.ThreadPoolExecutor’ subclass providing asynchronous run and submit methods that support kwargs, with support for synchronous mode
Examples
>>> executor = AsyncThreadPoolExecutor(max_workers=10, thread_name_prefix="MyThread") >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]
Initializes the AsyncThreadPoolExecutor.
- Parameters:
max_workers (int | None) – The maximum number of workers. Defaults to None.
thread_name_prefix (str) – Prefix for thread names. Defaults to ‘’.
initializer (Callable[[...], object] | None) – An initializer callable. Defaults to None.
initargs (Tuple[Any, ...]) – Arguments for the initializer. Defaults to ().
- Return type:
None
Examples
>>> executor = AsyncThreadPoolExecutor(max_workers=10, thread_name_prefix="MyThread") >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_thread_count()
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _initializer_failed()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _broken
- _counter = <method-wrapper '__next__' of itertools.count object>
- _idle_semaphore
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _shutdown
- _shutdown_lock
- _thread_name_prefix
- _threads
- _work_queue
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- class a_sync.executor.PruningThreadPoolExecutor[source]
Bases:
AsyncThreadPoolExecutor
This
AsyncThreadPoolExecutor
implementation prunes inactive threads after ‘timeout’ seconds without a work item. Pruned threads will be automatically recreated as needed for future workloads. Up to ‘max_threads’ can be active at any one time. The executor ensures that at least one active thread remains to prevent locks.Note
The _worker function includes a check (len(executor) > 1) to ensure that at least one thread remains active. This prevents the executor from having zero active threads, which could lead to deadlocks.
Examples
>>> executor = PruningThreadPoolExecutor(max_workers=5, timeout=300) >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=(), timeout=600)[source]
Initializes the PruningThreadPoolExecutor.
- Parameters:
max_workers – The maximum number of workers. Defaults to None.
thread_name_prefix – Prefix for thread names. Defaults to ‘’.
initializer – An initializer callable. Defaults to None.
initargs – Arguments for the initializer. Defaults to ().
timeout – Timeout duration for pruning inactive threads. Defaults to TEN_MINUTES.
Examples
>>> executor = PruningThreadPoolExecutor(max_workers=5, timeout=300) >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_thread_count()[source]
Adjusts the number of threads based on workload and idle threads.
See also
_worker()
for the worker function that handles thread pruning.
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _initializer_failed()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _adjusting_lock
Lock used to adjust the number of threads.
- _broken
- _counter = <method-wrapper '__next__' of itertools.count object>
- _idle_semaphore
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _shutdown
- _shutdown_lock
- _thread_name_prefix
- _threads
- _timeout
Timeout duration for pruning inactive threads.
- _work_queue
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
a_sync.future module
The future.py module provides functionality for handling asynchronous futures, including a decorator for converting callables into ASyncFuture objects and utilities for managing asynchronous computations.
- Functions:
- future(callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]) -> Callable[P, Union[T, “ASyncFuture[T]”]]:
A decorator to convert a callable into an ASyncFuture, with optional modifiers.
- _gather_check_and_materialize(*things: Unpack[MaybeAwaitable[T]]) -> List[T]:
Gathers and materializes a list of awaitable or non-awaitable items.
- _check_and_materialize(thing: T) -> T:
Checks if an item is awaitable and materializes it.
- _materialize(meta: “ASyncFuture[T]”) -> T:
Materializes the result of an ASyncFuture.
- Classes:
ASyncFuture: Represents an asynchronous future result.
TODO include a simple mathematics example a one complex example with numerous variables and operations TODO include attribute access examples TODO describe a bit more about both of the above 2 TODOs somewhere in this module-level docstring TODO describe why a user would want to use these (to write cleaner code that doesn’t require as many ugly gathers) TODO include comparisons between the ‘new way’ with this future class and the ‘old way’ with gathers
- class a_sync.future.ASyncFuture[source]
Bases:
Future
,Awaitable
[T
]A class representing an asynchronous future result.
Inherits from both concurrent.futures.Future and Awaitable[T], allowing it to be used in both synchronous and asynchronous contexts.
The ASyncFuture class provides additional functionality for arithmetic operations, comparisons, and conversions, making it versatile for various use cases.
Example
>>> async def async_fn(): ... return 42 >>> future = ASyncFuture(async_fn()) >>> await future 42
Note
Arithmetic operations are implemented, allowing for mathematical operations on future results. You no longer have to choose between optimized async code and clean, readable code.
Example
>>> future1 = ASyncFuture(asyncio.sleep(1, result=10)) >>> future2 = ASyncFuture(asyncio.sleep(1, result=5)) >>> future3 = ASyncFuture(asyncio.sleep(1, result=10)) >>> future4 = ASyncFuture(asyncio.sleep(1, result=2)) >>> result = (future1 + future2) / future3 ** future4 >>> await result 0.15
- Attribute Access:
The ASyncFuture allows attribute access on the materialized result.
Example
>>> class Example: ... def __init__(self, value): ... self.value = value >>> future = ASyncFuture(asyncio.sleep(1, result=Example(42))) >>> future.value 42
See also
future()
for creating ASyncFuture instances.- __getitem__(key)[source]
Allows item access on the materialized result.
- Parameters:
key – The key to access.
- Returns:
The item from the materialized result.
- Return type:
Example
>>> future = ASyncFuture(asyncio.sleep(1, result={'key': 'value'})) >>> future['key'] 'value'
- __init__(awaitable, dependencies=[])[source]
Initializes an ASyncFuture with an awaitable and optional dependencies.
- Parameters:
awaitable (Awaitable[T]) – The awaitable object.
dependencies (List[ASyncFuture]) – A list of dependencies. Defaults to [].
- Return type:
None
Example
>>> async def async_fn(): ... return 42 >>> future = ASyncFuture(async_fn()) >>> await future 42
- __iter__()[source]
Returns an iterator for the materialized result.
Example
>>> future = ASyncFuture(asyncio.sleep(1, result=[1, 2, 3])) >>> for item in future: ... print(item) 1 2 3
- __next__()[source]
Returns the next item from the materialized result.
Example
>>> future = ASyncFuture(asyncio.sleep(1, result=iter([1, 2, 3]))) >>> next(future) 1
- _invoke_callbacks()
- add_done_callback(fn)
Attaches a callable that will be called when the future finishes.
- Parameters:
fn – A callable that will be called with this future as its only argument when the future completes or is cancelled. The callable will always be called by a thread in the same process in which it was added. If the future has already completed or been cancelled then the callable will be called immediately. These callables are called in the order that they were added.
- cancel()
Cancel the future if possible.
Returns True if the future was cancelled, False otherwise. A future cannot be cancelled if it is running or has already completed.
- cancelled()
Return True if the future was cancelled.
- done()
Return True if the future was cancelled or finished executing.
- exception(timeout=None)
Return the exception raised by the call that the future represents.
- Parameters:
timeout – The number of seconds to wait for the exception if the future isn’t done. If None, then there is no limit on the wait time.
- Returns:
The exception raised by the call that the future represents or None if the call completed without raising.
- Raises:
CancelledError – If the future was cancelled.
TimeoutError – If the future didn’t finish executing before the given timeout.
- running()
Return True if the future is currently executing.
- set_exception(exception)
Sets the result of the future as being the given exception.
Should only be used by Executor implementations and unit tests.
- set_result(result)
Sets the return value of work associated with the future.
Should only be used by Executor implementations and unit tests.
- set_running_or_notify_cancel()
Mark the future as running or process any cancel notifications.
Should only be used by Executor implementations and unit tests.
If the future has been cancelled (cancel() was called and returned True) then any threads waiting on the future completing (though calls to as_completed() or wait()) are notified and False is returned.
If the future was not cancelled then it is put in the running state (future calls to running() will return True) and True is returned.
This method should be called by Executor implementations before executing the work associated with this future. If this method returns False then the work should not be executed.
- Returns:
False if the Future was cancelled, True otherwise.
- Raises:
RuntimeError – if this method was already called or if set_result() or set_exception() was called.
- property result: Callable[[], T] | Any
If this future is not done, it will work like cf.Future.result. It will block, await the awaitable, and return the result when ready. If this future is done and the result has attribute result, will return getattr(future_result, ‘result’) If this future is done and the result does NOT have attribute result, will again work like cf.Future.result
Example
>>> future = ASyncFuture(asyncio.sleep(1, result=42)) >>> future.result() 42
- a_sync.future.future(callable=None, **kwargs)[source]
A decorator function to convert a callable into an ASyncFuture, with optional modifiers.
This function wraps the provided callable in an _ASyncFutureWrappedFn instance, which returns an ASyncFuture when called. The ASyncFuture allows the result of the callable to be awaited or accessed synchronously.
- Parameters:
callable (Callable[[~P], Awaitable[T]] | Callable[[~P], T] | None) – The callable to convert. Defaults to None.
**kwargs (Unpack[ModifierKwargs]) – Additional keyword arguments for the modifier.
- Returns:
A callable that returns either the result or an ASyncFuture.
- Return type:
Callable[[~P], T | ASyncFuture[T]]
Example
>>> @future ... async def async_function(): ... return 42 >>> result = async_function() >>> isinstance(result, ASyncFuture) True
See also
a_sync.iter module
- class a_sync.iter.ASyncFilter
Bases:
_ASyncView
[T
]An async filter class that filters items of an async iterable based on a provided function.
This class inherits from
_ASyncView
and provides the functionality to asynchronously iterate over items, applying the filter function to each item to determine if it should be included in the result. The filter function can be either synchronous or asynchronous.- Example:
>>> async def is_even(x): ... return x % 2 == 0 >>> filtered_iterable = ASyncFilter(is_even, some_async_iterable) >>> async for item in filtered_iterable: ... print(item)
- See Also:
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncFilter(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) Self
Return the {cls} for aiteration.
- Return type:
Self
- async __anext__(self) T
- Return type:
T
- __init__(self, function: ViewFn[T], iterable: AnyIterable[T]) None
Initializes the {cls} with a function and an iterable.
- __iter__(self) Self
Return the {cls} for iteration.
Note
Synchronous iteration uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Self
- __next__(self) T
Synchronously fetch the next item from the {cls}.
Note
This method uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Raises:
StopIteration – Once all {obj} have been fetched from the {cls}.
SyncModeInAsyncContextError – If the event loop is already running.
- Return type:
T
- async _check(self, obj: T) bool
Checks if an object passes the filter function.
- Parameters:
obj (T) – The object to check.
- Returns:
True if the object passes the filter, False otherwise.
- Return type:
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped)
Class method to wrap either an AsyncIterator or an async generator function.
- class a_sync.iter.ASyncGeneratorFunction
-
Encapsulates an asynchronous generator function, providing a mechanism to use it as an asynchronous iterator with enhanced capabilities. This class wraps an async generator function, allowing it to be called with parameters and return an
ASyncIterator
object. It is particularly useful for situations where an async generator function needs to be used in a manner that is consistent with both synchronous and asynchronous execution contexts.The ASyncGeneratorFunction class supports dynamic binding to instances, enabling it to be used as a method on class instances. When accessed as a descriptor, it automatically handles the binding to the instance, thereby allowing the wrapped async generator function to be invoked with instance context (‘self’) automatically provided. This feature is invaluable for designing classes that need to expose asynchronous generators as part of their interface while maintaining the ease of use and calling semantics similar to regular methods.
By providing a unified interface to asynchronous generator functions, this class facilitates the creation of APIs that are flexible and easy to use in a wide range of asynchronous programming scenarios. It abstracts away the complexities involved in managing asynchronous generator lifecycles and invocation semantics, making it easier for developers to integrate asynchronous iteration patterns into their applications.
Example
>>> async def my_async_gen(): ... yield 1 ... yield 2 >>> async_gen_func = ASyncGeneratorFunction(my_async_gen) >>> for item in async_gen_func(): ... print(item)
See also
- __call__(self, *args: P.args, **kwargs: P.kwargs) ASyncIterator[T]
Calls the wrapped async generator function with the given arguments and keyword arguments, returning an
ASyncIterator
.- Parameters:
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
- __init__(self, async_gen_func: AsyncGenFunc[P, T], instance: Any = None) None
Initializes the ASyncGeneratorFunction with the given async generator function and optionally an instance.
- Parameters:
async_gen_func (Callable[[~P], AsyncGenerator[T, None] | AsyncIterator[T]]) – The async generator function to wrap.
instance (optional) – The object to bind to the function, if applicable.
- Return type:
None
- _cache_handle: TimerHandle
- class a_sync.iter.ASyncIterable
Bases:
_AwaitableAsyncIterableMixin
[T
],Iterable
[T
]A hybrid Iterable/AsyncIterable implementation designed to offer dual compatibility with both synchronous and asynchronous iteration protocols.
This class allows objects to be iterated over using either a standard for loop or an async for loop, making it versatile in scenarios where the mode of iteration (synchronous or asynchronous) needs to be flexible or is determined at runtime.
The class achieves this by implementing both __iter__ and __aiter__ methods, enabling it to return appropriate iterator objects that can handle synchronous and asynchronous iteration, respectively. However, note that synchronous iteration relies on the
ASyncIterator
class, which uses asyncio.get_event_loop().run_until_complete to fetch items. This can raise a RuntimeError if the event loop is already running, and in such cases, aSyncModeInAsyncContextError
is raised from the RuntimeError.- Example:
>>> async_iterable = ASyncIterable(some_async_iterable) >>> async for item in async_iterable: ... print(item) >>> for item in async_iterable: ... print(item)
- See Also:
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncIterable(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) AsyncIterator[T]
Return an async iterator that yields {obj} from the {cls}.
- Return type:
- __init__(self, async_iterable: AsyncIterable[T])
Initializes the ASyncIterable with an async iterable.
- Parameters:
async_iterable (AsyncIterable[T]) – The async iterable to wrap.
- __iter__(self) Iterator[T]
Return an iterator that yields {obj} from the {cls}.
Note
Synchronous iteration leverages
ASyncIterator
, which usesasyncio.BaseEventLoop.run_until_complete()
to fetch items.ASyncIterator.__next__()
raises aSyncModeInAsyncContextError
if the event loop is already running.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Iterator[T]
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped: AsyncIterable[T]) 'ASyncIterable[T]'
Class method to wrap an AsyncIterable for backward compatibility.
- Parameters:
wrapped (AsyncIterable[T])
- Return type:
- class a_sync.iter.ASyncIterator
Bases:
_AwaitableAsyncIterableMixin
[T
],Iterator
[T
]A hybrid Iterator/AsyncIterator implementation that bridges the gap between synchronous and asynchronous iteration. This class provides a unified interface for iteration that can seamlessly operate in both synchronous (for loop) and asynchronous (async for loop) contexts. It allows the wrapping of asynchronous iterable objects or async generator functions, making them usable in synchronous code without explicitly managing event loops or asynchronous context switches.
By implementing both __next__ and __anext__ methods, ASyncIterator enables objects to be iterated using standard iteration protocols while internally managing the complexities of asynchronous iteration. This design simplifies the use of asynchronous iterables in environments or frameworks that are not inherently asynchronous, such as standard synchronous functions or older codebases being gradually migrated to asynchronous IO.
- Note:
Synchronous iteration with ASyncIterator uses asyncio.get_event_loop().run_until_complete, which can raise a RuntimeError if the event loop is already running. In such cases, a
SyncModeInAsyncContextError
is raised from the RuntimeError, indicating that synchronous iteration is not possible in an already running event loop.- Example:
>>> async_iterator = ASyncIterator(some_async_iterator) >>> async for item in async_iterator: ... print(item) >>> for item in async_iterator: ... print(item)
- See Also:
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncIterator(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) Self
Return the {cls} for aiteration.
- Return type:
Self
- __anext__(self) Coroutine[Any, Any, T]
Asynchronously fetch the next item from the {cls}.
- Raises:
StopAsyncIteration – Once all {obj} have been fetched from the {cls}.
- Return type:
- __init__(self, async_iterator: AsyncIterator[T])
Initializes the ASyncIterator with an async iterator.
- Parameters:
async_iterator (AsyncIterator[T]) – The async iterator to wrap.
- __iter__(self) Self
Return the {cls} for iteration.
Note
Synchronous iteration uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Self
- __next__(self) T
Synchronously fetch the next item from the {cls}.
Note
This method uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Raises:
StopIteration – Once all {obj} have been fetched from the {cls}.
SyncModeInAsyncContextError – If the event loop is already running.
- Return type:
T
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped)
Class method to wrap either an AsyncIterator or an async generator function.
- class a_sync.iter.ASyncSorter
Bases:
_ASyncView
[T
]An async sorter class that sorts items of an async iterable based on a provided key function.
This class inherits from
_ASyncView
and provides the functionality to asynchronously iterate over items, applying the key function to each item for sorting. The key function can be either synchronous or asynchronous. Note that the ASyncSorter instance can only be consumed once.- Example:
>>> sorted_iterable = ASyncSorter(some_async_iterable, key=lambda x: x.value) >>> async for item in sorted_iterable: ... print(item)
- See Also:
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncSorter(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) AsyncIterator[T]
Return an async iterator for the {cls}.
- Raises:
RuntimeError – If the ASyncSorter instance has already been consumed.
- Returns:
An async iterator that will yield the sorted {obj}.
- Return type:
- __anext__(self) T
- Return type:
T
- __init__(self, iterable: AsyncIterable[T], *, key: SortKey[T] = None, reverse: bool = False) None
Initializes the ASyncSorter with an iterable and an optional sorting configuration (key function, and reverse flag).
- Parameters:
iterable (AsyncIterable[T]) – The async iterable to sort.
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If none is provided, elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the list elements will be sorted in reverse order. Defaults to False.
- Return type:
None
- __iter__(self) Self
Return the {cls} for iteration.
Note
Synchronous iteration uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Self
- __next__(self) T
Synchronously fetch the next item from the {cls}.
Note
This method uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Raises:
StopIteration – Once all {obj} have been fetched from the {cls}.
SyncModeInAsyncContextError – If the event loop is already running.
- Return type:
T
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped)
Class method to wrap either an AsyncIterator or an async generator function.
a_sync.task module
This module provides asynchronous task management utilities, specifically focused on creating and handling mappings of tasks.
The main components include: - TaskMapping: A class for managing and asynchronously generating tasks based on input iterables. - TaskMappingKeys: A view to asynchronously iterate over the keys of a TaskMapping. - TaskMappingValues: A view to asynchronously iterate over the values of a TaskMapping. - TaskMappingItems: A view to asynchronously iterate over the items (key-value pairs) of a TaskMapping.
- class a_sync.task.TaskMapping[source]
Bases:
DefaultDict
[K
,asyncio.Task[V]
],AsyncIterable
[Tuple
[K
,V
]]A mapping of keys to asynchronous tasks with additional functionality.
TaskMapping is a specialized dictionary that maps keys to asyncio Tasks. It provides convenient methods for creating, managing, and iterating over these tasks asynchronously.
Tasks are created automatically for each key using a provided function. You cannot manually set items in a TaskMapping using dictionary-like syntax.
Example
>>> async def fetch_data(url: str) -> str: ... async with aiohttp.ClientSession() as session: ... async with session.get(url) as response: ... return await response.text() ... >>> tasks = TaskMapping(fetch_data, ['http://example.com', 'https://www.python.org'], name='url_fetcher', concurrency=5) >>> async for key, result in tasks: ... print(f"Data for {key}: {result}") ... Data for python.org: http://python.org Data for example.com: http://example.com
Note
You cannot manually set items in a TaskMapping using dictionary-like syntax. Tasks are created and managed internally.
- async __aiter__(pop=False)[source]
Asynchronously iterate through all key-task pairs, yielding the key-result pair as each task completes.
- Parameters:
pop (bool)
- Return type:
AsyncIterator[Tuple[K, V]]
- __init__(wrapped_func=None, *iterables, name='', concurrency=None, **wrapped_func_kwargs)[source]
Initialize a TaskMapping instance.
- Parameters:
wrapped_func (Callable[[Concatenate[K, ~P]], Awaitable[V]] | None) – A callable that takes a key and additional parameters and returns an Awaitable.
*iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]]) – Any number of iterables whose elements will be used as keys for task generation.
name (str) – An optional name for the tasks created by this mapping.
concurrency (int | None) – Maximum number of tasks to run concurrently.
**wrapped_func_kwargs (~P) – Additional keyword arguments to be passed to wrapped_func.
- Return type:
None
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item, [1, 2, 3], concurrency=2)
- __iter__()
Implement iter(self).
- _start_tasks_for_iterables(*iterables)[source]
Start new tasks for each key in the provided iterables.
- Parameters:
iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]])
- Return type:
AsyncIterator[Tuple[K, Task[V]]]
- _tasks_for_iterables(*iterables)[source]
Ensure tasks are running for each key in the provided iterables.
- Parameters:
iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]])
- Return type:
AsyncIterator[Tuple[K, Task[V]]]
- copy() a shallow copy of D.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingValues[K, V]
- keys() a set-like object providing a view on D's keys [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingKeys[K, V]
- map(*iterables, pop=True, yields='both')[source]
Asynchronously map iterables to tasks and yield their results.
- Parameters:
*iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]]) – Iterables to map over.
pop (bool) – Whether to remove tasks from the internal storage once they are completed.
yields (Literal['keys', 'both']) – Whether to yield ‘keys’, ‘values’, or ‘both’ (key-value pairs).
- Yields:
Depending on yields, either keys, values, or tuples of key-value pairs representing the results of completed tasks.
- Return type:
AsyncIterator[Tuple[K, V]]
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item) async for key, result in task_map.map([1, 2, 3]):
print(f”Processed {key}: {result}”)
- pop(*args, cancel=False)[source]
Pop a task from the TaskMapping.
- Parameters:
*args (K) – One key to pop.
cancel (bool) – Whether to cancel the task when popping it.
- Return type:
Task[V] | Future[V]
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingValues[K, V]
- yield_completed(pop=True)[source]
Asynchronously yield tuples of key-value pairs representing the results of any completed tasks.
- Parameters:
pop (bool) – Whether to remove tasks from the internal storage once they are completed.
- Yields:
Tuples of key-value pairs representing the results of completed tasks.
- Return type:
AsyncIterator[Tuple[K, V]]
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item, [1, 2, 3]) async for key, result in task_map.yield_completed():
print(f”Completed {key}: {result}”)
- _destroyed: bool = False
Boolean indicating whether his mapping has been consumed and is no longer usable for aggregations.
- property _init_loader: Task[None] | None
An asyncio Task used to preload values from the iterables.
- _init_loader_next: Callable[[], Awaitable[Tuple[Tuple[K, Task[V]]]]] | None = None
A coro function that blocks until the _init_loader starts a new task(s), and then returns a Tuple[Tuple[K, asyncio.Task[V]]] with all of the new tasks and the keys that started them.
- _next: CythonEvent = None
An asyncio Event that indicates the next result is ready
- property _queue: ProcessingQueue
- _wrapped_func
The function used to create tasks for each key.
- default_factory
Factory for default value called by __missing__().
- class a_sync.task.TaskMappingItems[source]
Bases:
_TaskMappingView
[Tuple
[K
,V
],K
,V
],Generic
[K
,V
]Asynchronous view to iterate over the items (key-value pairs) of a TaskMapping.
- async __aiter__()[source]
- Return type:
AsyncIterator[Tuple[K, V]]
- __init__(self)
- Parameters:
view (Iterable[T])
task_mapping (TaskMapping[K, V])
pop (bool)
- Return type:
None
- _get_from_item(item)
- class a_sync.task.TaskMappingKeys[source]
Bases:
_TaskMappingView
[K
,K
,V
],Generic
[K
,V
]Asynchronous view to iterate over the keys of a TaskMapping.
- __init__(self)
- Parameters:
view (Iterable[T])
task_mapping (TaskMapping[K, V])
pop (bool)
- Return type:
None
- _get_from_item(item)
- class a_sync.task.TaskMappingValues[source]
Bases:
_TaskMappingView
[V
,K
,V
],Generic
[K
,V
]Asynchronous view to iterate over the values of a TaskMapping.
- __init__(self)
- Parameters:
view (Iterable[T])
task_mapping (TaskMapping[K, V])
pop (bool)
- Return type:
None
- _get_from_item(item)
Module contents
This module initializes the a_sync library by importing and organizing various components, utilities, and classes. It provides a convenient and unified interface for asynchronous programming with a focus on flexibility and efficiency.
The a_sync library offers decorators and base classes to facilitate writing both synchronous and asynchronous code. It includes the @a_sync() decorator and the ASyncGenericBase class, which allow for creating functions and classes that can operate in both synchronous and asynchronous contexts. Additionally, it provides enhanced asyncio primitives, such as queues and locks, with extra functionality.
- Modules and components included:
aliases
,exceptions
,iter
,task
: Core modules of the library.ASyncGenericBase
,ASyncGenericSingleton
,a_sync()
: Base classes and decorators for dual-context execution.ASyncCachedPropertyDescriptor
,ASyncPropertyDescriptor
, cached_property, property: Property descriptors for async properties.as_completed()
,create_task()
,gather()
: Enhanced asyncio functions.Executors:
AsyncThreadPoolExecutor
,AsyncProcessPoolExecutor
,PruningThreadPoolExecutor
for async execution.Iterators:
ASyncIterable
,ASyncIterator
,filter
,sorted
for async iteration.Utilities:
all()
,any()
,as_yielded()
for async utilities.apply_semaphore()
: Function to apply semaphores to coroutines.
Alias for backward compatibility:
- ASyncBase
is an alias for ASyncGenericBase
, which will be removed eventually, probably in version 0.1.0.
Examples
Using the @a_sync decorator: >>> from a_sync import a_sync >>> @a_sync … async def my_function(): … return “Hello, World!” >>> result = await my_function() >>> print(result)
Using ASyncGenericBase for dual-context classes: >>> from a_sync import ASyncGenericBase >>> class MyClass(ASyncGenericBase): … async def my_method(self): … return “Hello from MyClass” >>> obj = MyClass() >>> result = await obj.my_method() >>> print(result)
See also
a_sync.a_sync
: Contains the core classes and decorators.a_sync.asyncio
: Provides enhanced asyncio functions.a_sync.primitives
: Includes modified versions of standard asyncio primitives.
- class a_sync.ASyncCachedPropertyDescriptor
Bases:
_ASyncPropertyDescriptorBase
[I
,T
],AsyncCachedPropertyDescriptor
A descriptor class for dual-function sync/async cached properties.
This class extends the API of ASyncPropertyDescriptor to provide caching functionality, storing the computed value after the first access.
- __init__(self, _fget: AsyncGetterFunction[I, T], _fset=None, _fdel=None, field_name=None, **modifiers: Unpack[ModifierKwargs]) None
Initializes the ASyncCachedPropertyDescriptor.
- Parameters:
_fget (Callable[[I], Awaitable[T]]) – The function to be wrapped.
_fset – Optional setter function for the property.
_fdel – Optional deleter function for the property.
field_name – Optional name for the field. If not provided, the function’s name will be used.
**modifiers (Unpack[ModifierKwargs]) – Additional modifier arguments.
- Return type:
None
- async _all(*instances, concurrency=None, name='', **kwargs)
Check if all results are truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._all([1, 2, 3]) ```
- async _any(*instances, concurrency=None, name='', **kwargs)
Check if any result is truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._any([-1, 0, 1]) ```
- _asyncify(self, func: SyncFn[P, T]) CoroFn[P, T]
Converts a synchronous function to an asynchronous one and applies async modifiers.
- Parameters:
func (Callable[[~P], T]) – The synchronous function to be converted.
- Returns:
The asynchronous version of the function with applied modifiers.
- Return type:
See also
ModifierManager.apply_async_modifiers()
- _check_method_name(method, method_type)
- _check_method_sync(method, method_type)
- async _max(*instances, concurrency=None, name='', **kwargs)
Find the maximum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._max([3, 1, 2]) ```
- async _min(*instances, concurrency=None, name='', **kwargs)
Find the minimum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._min([3, 1, 2]) ```
- async _sum(*instances, concurrency=None, name='', **kwargs)
Calculate the sum of results.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._sum([1, 2, 3]) ```
- already_loaded(instance)
- del_cache_value(instance)
- deleter(method)
- async get(self, instance: I, owner: Type[I] | None = None) T
Asynchronously retrieves the property value.
- get_cache(instance)
- get_cache_value(instance)
- get_instance_state(instance)
- get_lock(self, instance: I) 'asyncio.Task[T]'
Retrieves the lock for the property.
- Parameters:
instance (I) – The instance from which the property is accessed.
- Returns:
An asyncio Task representing the lock.
- Return type:
Task[T]
- has_cache_value(instance)
- map(self, instances: AnyIterable[I], owner: Optional[Type[I]] = None, concurrency: Optional[int] = None, unicode name: str = u'') 'TaskMapping[I, T]'
Maps the property across multiple instances.
- not_loaded(instance)
- pop_lock(self, instance: I) None
Removes the lock for the property.
- Parameters:
instance (I) – The instance from which the property is accessed.
- Return type:
None
- set_cache_value(instance, value)
- setter(method)
- property _TaskMapping: Type[TaskMapping]
This silly helper just fixes a circular import
- property _await: Callable[[Awaitable[T]], T]
Applies sync modifiers to the _helpers._await function and caches it.
- Returns:
The modified _await function.
See also
ModifierManager.apply_sync_modifiers()
- property all: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if all results are truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.all([1, 2, 3])
- property any: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if any result is truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.any([-1, 0, 1])
- property default: Literal['sync', 'async', None]
Gets the default execution mode (sync, async, or None) for the function.
- Returns:
The default execution mode.
See also
ModifierManager.default
- field_name
The name of the field the
ASyncDescriptor
is bound to.
- property max: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the maximum result.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.max([3, 1, 2])
- property min: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the minimum result.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.min([3, 1, 2]) ```
- modifiers
- property sum: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the sum of results.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.sum([1, 2, 3]) ```
- wrapped
- class a_sync.ASyncGenericSingleton[source]
Bases:
ASyncGenericBase
A base class for creating singleton-esque ASync classes.
This class combines the functionality of
ASyncGenericBase
with a singleton pattern, ensuring that only one instance of the class exists per execution mode (sync/async). It uses a custom metaclassASyncSingletonMeta
to manage instance creation and caching.Subclasses of
ASyncGenericSingleton
will have two instances instead of one: - one synchronous instance - one asynchronous instanceThis allows for proper behavior in both synchronous and asynchronous contexts while maintaining the singleton pattern within each context.
Note
This class can be instantiated directly, but it is intended to be subclassed to define specific asynchronous behavior. Subclasses should define the necessary properties and methods to specify the asynchronous behavior, as outlined in
ASyncGenericBase
.Example
Create a subclass of ASyncGenericSingleton to define specific behavior:
class MyAsyncSingleton(ASyncGenericSingleton): @property def __a_sync_flag_name__(self): return "asynchronous" @property def __a_sync_flag_value__(self): return self.asynchronous @classmethod def __a_sync_default_mode__(cls): return False @a_sync def my_method(self): # Method implementation # These will return the same synchronous instance sync_instance1 = MyAsyncSingleton(sync=True) sync_instance2 = MyAsyncSingleton(sync=True) # These will return the same asynchronous instance async_instance1 = MyAsyncSingleton(asynchronous=True) async_instance2 = MyAsyncSingleton(asynchronous=True) assert sync_instance1 is sync_instance2 assert async_instance1 is async_instance2 assert sync_instance1 is not async_instance1
See also
ASyncGenericBase
for base functionality.ASyncSingletonMeta
for the metaclass managing the singleton behavior.
- __init__(self)
- class a_sync.ASyncIterable
Bases:
_AwaitableAsyncIterableMixin
[T
],Iterable
[T
]A hybrid Iterable/AsyncIterable implementation designed to offer dual compatibility with both synchronous and asynchronous iteration protocols.
This class allows objects to be iterated over using either a standard for loop or an async for loop, making it versatile in scenarios where the mode of iteration (synchronous or asynchronous) needs to be flexible or is determined at runtime.
The class achieves this by implementing both __iter__ and __aiter__ methods, enabling it to return appropriate iterator objects that can handle synchronous and asynchronous iteration, respectively. However, note that synchronous iteration relies on the
ASyncIterator
class, which uses asyncio.get_event_loop().run_until_complete to fetch items. This can raise a RuntimeError if the event loop is already running, and in such cases, aSyncModeInAsyncContextError
is raised from the RuntimeError.- Example:
>>> async_iterable = ASyncIterable(some_async_iterable) >>> async for item in async_iterable: ... print(item) >>> for item in async_iterable: ... print(item)
- See Also:
ASyncFilter
ASyncSorter
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncIterable(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) AsyncIterator[T]
Return an async iterator that yields {obj} from the {cls}.
- Return type:
- __init__(self, async_iterable: AsyncIterable[T])
Initializes the ASyncIterable with an async iterable.
- Parameters:
async_iterable (AsyncIterable[T]) – The async iterable to wrap.
- __iter__(self) Iterator[T]
Return an iterator that yields {obj} from the {cls}.
Note
Synchronous iteration leverages
ASyncIterator
, which usesasyncio.BaseEventLoop.run_until_complete()
to fetch items.ASyncIterator.__next__()
raises aSyncModeInAsyncContextError
if the event loop is already running.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Iterator[T]
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped: AsyncIterable[T]) 'ASyncIterable[T]'
Class method to wrap an AsyncIterable for backward compatibility.
- Parameters:
wrapped (AsyncIterable[T])
- Return type:
- class a_sync.ASyncIterator
Bases:
_AwaitableAsyncIterableMixin
[T
],Iterator
[T
]A hybrid Iterator/AsyncIterator implementation that bridges the gap between synchronous and asynchronous iteration. This class provides a unified interface for iteration that can seamlessly operate in both synchronous (for loop) and asynchronous (async for loop) contexts. It allows the wrapping of asynchronous iterable objects or async generator functions, making them usable in synchronous code without explicitly managing event loops or asynchronous context switches.
By implementing both __next__ and __anext__ methods, ASyncIterator enables objects to be iterated using standard iteration protocols while internally managing the complexities of asynchronous iteration. This design simplifies the use of asynchronous iterables in environments or frameworks that are not inherently asynchronous, such as standard synchronous functions or older codebases being gradually migrated to asynchronous IO.
- Note:
Synchronous iteration with ASyncIterator uses asyncio.get_event_loop().run_until_complete, which can raise a RuntimeError if the event loop is already running. In such cases, a
SyncModeInAsyncContextError
is raised from the RuntimeError, indicating that synchronous iteration is not possible in an already running event loop.- Example:
>>> async_iterator = ASyncIterator(some_async_iterator) >>> async for item in async_iterator: ... print(item) >>> for item in async_iterator: ... print(item)
- See Also:
ASyncFilter
ASyncSorter
When awaited, a list of all
T
objects will be returned.Example
>>> my_object = ASyncIterator(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], T) True
- __aiter__(self) Self
Return the {cls} for aiteration.
- Return type:
Self
- __anext__(self) Coroutine[Any, Any, T]
Asynchronously fetch the next item from the {cls}.
- Raises:
StopAsyncIteration – Once all {obj} have been fetched from the {cls}.
- Return type:
- __init__(self, async_iterator: AsyncIterator[T])
Initializes the ASyncIterator with an async iterator.
- Parameters:
async_iterator (AsyncIterator[T]) – The async iterator to wrap.
- __iter__(self) Self
Return the {cls} for iteration.
Note
Synchronous iteration uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Self
- __next__(self) T
Synchronously fetch the next item from the {cls}.
Note
This method uses
asyncio.BaseEventLoop.run_until_complete()
to fetch {obj}. This raises aRuntimeError
if the event loop is already running. This RuntimeError will be caught and a more descriptiveSyncModeInAsyncContextError
will be raised in its place.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Raises:
StopIteration – Once all {obj} have been fetched from the {cls}.
SyncModeInAsyncContextError – If the event loop is already running.
- Return type:
T
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the {obj} yielded by the {cls} based on a function.
- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filtered {obj} from the {cls}.- Return type:
ASyncFilter[T]
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the {obj} yielded by the {cls}.
- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield the {obj} yielded from this {cls}, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped)
Class method to wrap either an AsyncIterator or an async generator function.
- class a_sync.ASyncPropertyDescriptor
Bases:
_ASyncPropertyDescriptorBase
[I
,T
],AsyncPropertyDescriptor
Descriptor class for asynchronous properties.
- __init__(self, _fget: AsyncGetterFunction[I, T], field_name: str | None = None, **modifiers: Unpack[ModifierKwargs]) None
Initializes the _ASyncPropertyDescriptorBase.
- Parameters:
_fget (Callable[[I], Awaitable[T]]) – The function to be wrapped.
field_name (str | None) – Optional name for the field. If not provided, the function’s name will be used.
**modifiers (Unpack[ModifierKwargs]) – Additional modifier arguments.
- Return type:
None
- async _all(*instances, concurrency=None, name='', **kwargs)
Check if all results are truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._all([1, 2, 3]) ```
- async _any(*instances, concurrency=None, name='', **kwargs)
Check if any result is truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._any([-1, 0, 1]) ```
- _asyncify(self, func: SyncFn[P, T]) CoroFn[P, T]
Converts a synchronous function to an asynchronous one and applies async modifiers.
- Parameters:
func (Callable[[~P], T]) – The synchronous function to be converted.
- Returns:
The asynchronous version of the function with applied modifiers.
- Return type:
See also
ModifierManager.apply_async_modifiers()
- async _max(*instances, concurrency=None, name='', **kwargs)
Find the maximum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._max([3, 1, 2]) ```
- async _min(*instances, concurrency=None, name='', **kwargs)
Find the minimum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._min([3, 1, 2]) ```
- async _sum(*instances, concurrency=None, name='', **kwargs)
Calculate the sum of results.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._sum([1, 2, 3]) ```
- awaitable_only(instance)
- async get(self, instance: I, owner: Type[I] | None = None) T
Asynchronously retrieves the property value.
- get_loader(instance)
- map(self, instances: AnyIterable[I], owner: Optional[Type[I]] = None, concurrency: Optional[int] = None, unicode name: str = u'') 'TaskMapping[I, T]'
Maps the property across multiple instances.
- property _TaskMapping: Type[TaskMapping]
This silly helper just fixes a circular import
- property _await: Callable[[Awaitable[T]], T]
Applies sync modifiers to the _helpers._await function and caches it.
- Returns:
The modified _await function.
See also
ModifierManager.apply_sync_modifiers()
- property all: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if all results are truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.all([1, 2, 3])
- property any: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if any result is truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.any([-1, 0, 1])
- property default: Literal['sync', 'async', None]
Gets the default execution mode (sync, async, or None) for the function.
- Returns:
The default execution mode.
See also
ModifierManager.default
- field_name
The name of the field the
ASyncDescriptor
is bound to.
- property max: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the maximum result.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.max([3, 1, 2])
- property min: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the minimum result.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.min([3, 1, 2]) ```
- modifiers
- property sum: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the sum of results.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.sum([1, 2, 3]) ```
- wrapped
- class a_sync.AsyncProcessPoolExecutor[source]
Bases:
_AsyncExecutorMixin
,ProcessPoolExecutor
A :class:`concurrent.futures.ProcessPoolExecutor’ subclass providing asynchronous run and submit methods that support kwargs, with support for synchronous mode
Examples
>>> executor = AsyncProcessPoolExecutor(max_workers=4) >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, mp_context=None, initializer=None, initargs=())[source]
Initializes the AsyncProcessPoolExecutor.
- Parameters:
max_workers (int | None) – The maximum number of workers. Defaults to None.
mp_context (BaseContext | None) – The multiprocessing context. Defaults to None.
initializer (Callable[[...], object] | None) – An initializer callable. Defaults to None.
initargs (Tuple[Any, ...]) – Arguments for the initializer. Defaults to ().
- Return type:
None
Examples
>>> executor = AsyncProcessPoolExecutor(max_workers=4) >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_process_count()
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _launch_processes()
- _spawn_process()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _start_executor_manager_thread()
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – If greater than one, the iterables will be chopped into chunks of size chunksize and submitted to the process pool. If set to one, the items in the list will be sent one at a time.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _broken
- _call_queue
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _mp_context
- _pending_work_items
- _processes
- _queue_count
- _queue_management_thread
- _queue_management_thread_wakeup
- _result_queue
- _shutdown_lock
- _shutdown_thread
- _work_ids
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- class a_sync.AsyncThreadPoolExecutor[source]
Bases:
_AsyncExecutorMixin
,ThreadPoolExecutor
A :class:`concurrent.futures.ThreadPoolExecutor’ subclass providing asynchronous run and submit methods that support kwargs, with support for synchronous mode
Examples
>>> executor = AsyncThreadPoolExecutor(max_workers=10, thread_name_prefix="MyThread") >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=())[source]
Initializes the AsyncThreadPoolExecutor.
- Parameters:
max_workers (int | None) – The maximum number of workers. Defaults to None.
thread_name_prefix (str) – Prefix for thread names. Defaults to ‘’.
initializer (Callable[[...], object] | None) – An initializer callable. Defaults to None.
initargs (Tuple[Any, ...]) – Arguments for the initializer. Defaults to ().
- Return type:
None
Examples
>>> executor = AsyncThreadPoolExecutor(max_workers=10, thread_name_prefix="MyThread") >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_thread_count()
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _initializer_failed()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _broken
- _counter = <method-wrapper '__next__' of itertools.count object>
- _idle_semaphore
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _shutdown
- _shutdown_lock
- _thread_name_prefix
- _threads
- _work_queue
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- class a_sync.CounterLock
Bases:
_DebugDaemonMixin
CounterLock(int start_value: int = 0, unicode name=u’’)
An async primitive that uses an internal counter to manage task synchronization.
A coroutine can await counter.wait_for(3) and it will wait until the internal counter >= 3. If some other task executes counter.value = 5 or counter.set(5), the first coroutine will proceed as 5 >= 3.
The internal counter can only be set to a value greater than the current value.
See also
CounterLockCluster
for managing multipleCounterLock
instances.- __init__()
Initializes the
CounterLock
with a starting value and an optional name.- Parameters:
start_value – The initial value of the counter.
name – An optional name for the counter, used in debug logs.
Examples
>>> counter = CounterLock(start_value=0, name="example_counter") >>> counter.value 0
- async _debug_daemon(self) None
Periodically logs debug information about the counter state and waiters.
This method is used internally to provide debugging information when debug logging is enabled.
- Return type:
None
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- is_ready(self, long long v) bool
A function that indicates whether the current counter value is greater than or equal to a given value.
- set(self, long long value) void
Sets the counter to the specified value.
This method internally uses the value property to enforce that the new value must be strictly greater than the current value.
- Parameters:
value – The value to set the counter to. Must be strictly greater than the current value.
- Raises:
ValueError – If the new value is less than or equal to the current value.
Examples
>>> counter = CounterLock(start_value=0) >>> counter.set(5) >>> counter.value 5
See also
CounterLock.value()
for direct value assignment.
- async wait_for(self, long long value) bint
Waits until the counter reaches or exceeds the specified value.
This method will ensure the debug daemon is running if the counter is not ready.
- Parameters:
value – The value to wait for.
- Return type:
bint
Examples
>>> counter = CounterLock(start_value=0) >>> await counter.wait_for(5) # This will block until counter.value >= 5
See also
CounterLock.set()
to set the counter value.
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _name
str
- Type:
CounterLock._name
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- value
int
Gets the current value of the counter.
Examples
>>> counter = CounterLock(start_value=0) >>> counter.value 0
- Type:
CounterLock.value
- a_sync.Event
alias of
CythonEvent
- class a_sync.PrioritySemaphore
Bases:
_AbstractPrioritySemaphore
PrioritySemaphore(int value: int = 1, name: Optional[str] = None, *) -> None Semaphore that uses numeric priorities for waiters.
This class extends
_AbstractPrioritySemaphore
and provides a concrete implementation using numeric priorities. The _context_manager_class is set to_PrioritySemaphoreContextManager
, and the _top_priority is set to -1, which is the highest priority.- Examples:
The primary way to use this semaphore is by specifying a priority.
>>> priority_semaphore = PrioritySemaphore(10) >>> async with priority_semaphore[priority]: ... await do_stuff()
You can also enter and exit this semaphore without specifying a priority, and it will use the top priority by default:
>>> priority_semaphore = PrioritySemaphore(10) >>> async with priority_semaphore: ... await do_stuff()
- See Also:
_AbstractPrioritySemaphore
for the base class implementation.
- __call__()
Decorator method to wrap coroutine functions with the semaphore.
This allows rewriting the pattern of acquiring a semaphore within a coroutine using a decorator.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- __getitem__()
Gets the context manager for a given priority.
- Parameters:
priority – The priority for which to get the context manager. If None, uses the top priority.
- Returns:
The context manager associated with the given priority.
Examples
>>> semaphore = _AbstractPrioritySemaphore(5) >>> context_manager = semaphore[priority]
- __init__(*args, **kwargs)
- async _debug_daemon(self) None
Daemon coroutine (runs in a background task) which will emit a debug log every minute while the semaphore has waiters.
This method is part of the
_DebugDaemonMixin
and is used to provide detailed logging information about the semaphore’s state when it is being waited on.Example
semaphore = Semaphore(5)
- async def monitor():
await semaphore._debug_daemon()
- Return type:
None
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _wake_up_next(self) None
Wakes up the next waiter in line.
This method handles the waking of waiters based on priority. It includes an emergency procedure to handle potential lost waiters, ensuring that no waiter is left indefinitely waiting.
The emergency procedure is a temporary measure to address potential issues with lost waiters.
Examples
>>> semaphore = _AbstractPrioritySemaphore(5) >>> semaphore._wake_up_next()
- Return type:
None
- async acquire(self) Literal[True]
Acquires the semaphore with the top priority.
This method overrides
Semaphore.acquire()
to handle priority-based logic.Examples
>>> semaphore = _AbstractPrioritySemaphore(5) >>> await semaphore.acquire()
- Return type:
Literal[True]
- decorate(self, fn: CoroFn[P, T]) CoroFn[P, T]
Wrap a coroutine function to ensure it runs with the semaphore.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- locked(self) bool
Checks if the semaphore is locked.
- Returns:
True if the semaphore cannot be acquired immediately, False otherwise.
Examples
>>> semaphore = _AbstractPrioritySemaphore(5) >>> semaphore.locked()
- release(self) void
Release a semaphore, incrementing the internal counter by one.
When it was zero on entry and another coroutine is waiting for it to become larger than zero again, wake up that coroutine.
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _value
int
- Type:
Semaphore._value
- _waiters
int
- Type:
Semaphore._waiters
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- name
str
- Type:
Semaphore.name
- a_sync.ProcessPoolExecutor
alias of
AsyncProcessPoolExecutor
- class a_sync.ProcessingQueue[source]
Bases:
_Queue
[Tuple
[P
,asyncio.Future[V]
]],Generic
[P
,V
]A queue designed for processing tasks asynchronously with multiple workers.
Each item in the queue is processed by a worker, and tasks can return results via asynchronous futures. This queue is ideal for scenarios where tasks need to be processed concurrently with a fixed number of workers.
Example
>>> async def process_task(data): return data.upper() >>> queue = ProcessingQueue(func=process_task, num_workers=5) >>> fut = await queue.put(item='task') >>> print(await fut) TASK
- __call__(*args, **kwargs)[source]
Submits a task to the queue.
Example
>>> fut = queue(*args, **kwargs) >>> print(fut)
- Parameters:
args (~P)
kwargs (~P)
- Return type:
Future[V]
- __init__(func, num_workers, *, return_data=True, name='', loop=None)[source]
Initializes a processing queue with the given worker function and worker count.
- Parameters:
func (Callable[[~P], Awaitable[V]]) – The task function to process.
num_workers (int) – Number of workers to process tasks.
return_data (bool) – Whether tasks should return data via futures. Defaults to True.
name (str) – Name of the queue. Defaults to an empty string.
loop (AbstractEventLoop | None) – Optional event loop for the queue.
- Return type:
None
Example
>>> queue = ProcessingQueue(func=my_task_func, num_workers=3, name='myqueue')
- _format()
- _get()
- _get_loop()
- _init(maxsize)
- _put(item)
- _wakeup_next(waiters)
- close()[source]
Closes the queue, preventing further task submissions.
Example
>>> queue.close()
- Return type:
None
- empty()
Return True if the queue is empty, False otherwise.
- full()
Return True if there are maxsize items in the queue.
Note: if the Queue was initialized with maxsize=0 (the default), then full() is never True.
- async get()
Remove and return an item from the queue.
If queue is empty, wait until an item is available.
- get_nowait()
Remove and return an item from the queue.
Return an item if one is immediately available, else raise QueueEmpty.
- async join()
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
- async put(*args, **kwargs)[source]
Asynchronously submits a task to the queue.
- Parameters:
args (~P) – Positional arguments for the task.
kwargs (~P) – Keyword arguments for the task.
- Returns:
The future result of the task.
- Return type:
Future[V]
Example
>>> fut = await queue.put(item='task') >>> print(await fut)
- put_nowait(*args, **kwargs)[source]
Immediately submits a task to the queue without waiting.
- Parameters:
args (~P) – Positional arguments for the task.
kwargs (~P) – Keyword arguments for the task.
- Returns:
The future result of the task.
- Return type:
Future[V]
Example
>>> fut = queue.put_nowait(item='task') >>> print(await fut)
- qsize()
Number of items in the queue.
- task_done()
Indicate that a formerly enqueued task is complete.
Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises ValueError if called more times than there were items placed in the queue.
- _finished
- _getters
- _loop = None
- _maxsize
- _name
Optional name for the queue.
- _no_futs
Indicates whether tasks will return data via futures.
- _putters
- _queue
- _unfinished_tasks
- _worker_coro
- func
The function that each worker will process.
- property maxsize
Number of items allowed in the queue.
- property name: str
Returns the name of the queue, or its representation.
Example
>>> print(queue.name)
- num_workers
The number of worker tasks for processing.
- class a_sync.PruningThreadPoolExecutor[source]
Bases:
AsyncThreadPoolExecutor
This
AsyncThreadPoolExecutor
implementation prunes inactive threads after ‘timeout’ seconds without a work item. Pruned threads will be automatically recreated as needed for future workloads. Up to ‘max_threads’ can be active at any one time. The executor ensures that at least one active thread remains to prevent locks.Note
The _worker function includes a check (len(executor) > 1) to ensure that at least one thread remains active. This prevents the executor from having zero active threads, which could lead to deadlocks.
Examples
>>> executor = PruningThreadPoolExecutor(max_workers=5, timeout=300) >>> future = executor.submit(some_function, arg1, arg2, kwarg1='kwarg1') >>> result = await future
- __init__(max_workers=None, thread_name_prefix='', initializer=None, initargs=(), timeout=600)[source]
Initializes the PruningThreadPoolExecutor.
- Parameters:
max_workers – The maximum number of workers. Defaults to None.
thread_name_prefix – Prefix for thread names. Defaults to ‘’.
initializer – An initializer callable. Defaults to None.
initargs – Arguments for the initializer. Defaults to ().
timeout – Timeout duration for pruning inactive threads. Defaults to TEN_MINUTES.
Examples
>>> executor = PruningThreadPoolExecutor(max_workers=5, timeout=300) >>> future = executor.submit(some_function, arg1, arg2) >>> result = await future
- _adjust_thread_count()[source]
Adjusts the number of threads based on workload and idle threads.
See also
_worker()
for the worker function that handles thread pruning.
- async _debug_daemon(fut, fn, *args, **kwargs)
Runs until manually cancelled by the finished work item.
- Parameters:
fut (Future) – The future being debugged.
fn – The function being executed.
*args – Positional arguments for the function.
**kwargs – Keyword arguments for the function.
- Return type:
None
See also
_start_debug_daemon()
to start the debug daemon.
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _initializer_failed()
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- map(fn, *iterables, timeout=None, chunksize=1)
Returns an iterator equivalent to map(fn, iter).
- Parameters:
fn – A callable that will take as many arguments as there are passed iterables.
timeout – The maximum number of seconds to wait. If None, then there is no limit on the wait time.
chunksize – The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor.
- Returns:
map(func, *iterables) but the calls may be evaluated out-of-order.
- Return type:
An iterator equivalent to
- Raises:
TimeoutError – If the entire result iterator could not be generated before the given timeout.
- async run(fn, *args, **kwargs)
A shorthand way to call await asyncio.get_event_loop().run_in_executor(this_executor, fn, *args). Doesn’t await this_executor.run(fn, *args) look so much better?
In synchronous mode, the function is executed directly in the current thread. In asynchronous mode, the function is submitted to the executor and awaited.
- Parameters:
fn (Callable[[~P], T]) – The function to run.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
Examples
>>> async def example(): >>> result = await executor.run(some_function, arg1, arg2, kwarg1=value1) >>> print(result)
See also
submit()
for submitting functions to the executor.
- shutdown(wait=True, *, cancel_futures=False)
Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
- Parameters:
wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
cancel_futures – If True then shutdown will cancel all pending futures. Futures that are completed or running will not be cancelled.
- submit(fn, *args, **kwargs)
Submits a job to the executor and returns an
asyncio.Future
that can be awaited for the result without blocking.- Parameters:
fn (Callable[[~P], T]) – The function to submit.
*args (~P) – Positional arguments for the function.
**kwargs (~P) – Keyword arguments for the function.
- Return type:
Future[T]
Examples
>>> future = executor.submit(some_function, arg1, arg2, kwarg1=value1) >>> result = await future >>> print(result)
See also
run()
for running functions with the executor.
- _adjusting_lock
Lock used to adjust the number of threads.
- _broken
- _counter = <method-wrapper '__next__' of itertools.count object>
- _idle_semaphore
- _initargs
- _initializer
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _shutdown
- _shutdown_lock
- _thread_name_prefix
- _threads
- _timeout
Timeout duration for pruning inactive threads.
- _work_queue
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- class a_sync.Queue[source]
Bases:
_Queue
[T
]A generic asynchronous queue that extends the functionality of asyncio.Queue.
This implementation supports retrieving multiple items at once and handling task processing in both FIFO and LIFO order. It provides enhanced type hinting support and additional methods for bulk operations.
- Inherits from:
Example
>>> queue = Queue() >>> await queue.put(item='task1') >>> await queue.put(item='task2') >>> result = await queue.get() >>> print(result) task1 >>> all_tasks = await queue.get_all() >>> print(all_tasks) ['task2']
- _get_loop()
- full()[source]
Return True if there are maxsize items in the queue.
Note: if the Queue was initialized with maxsize=0 (the default), then full() is never True.
- async get()[source]
Asynchronously retrieves and removes the next item from the queue.
If the queue is empty, this method will block until an item is available.
Example
>>> result = await queue.get() >>> print(result)
- Return type:
T
- async get_all()[source]
Asynchronously retrieves and removes all available items from the queue.
If the queue is empty, this method will wait until at least one item is available before returning.
Example
>>> tasks = await queue.get_all() >>> print(tasks)
- Return type:
List[T]
- get_all_nowait()[source]
Retrieves and removes all available items from the queue without waiting.
This method does not wait for items to be available and will raise an exception if the queue is empty.
- Raises:
QueueEmpty – If the queue is empty.
- Return type:
List[T]
Example
>>> tasks = queue.get_all_nowait() >>> print(tasks)
- async get_multi(i, can_return_less=False)[source]
Asynchronously retrieves up to i items from the queue.
- Parameters:
- Raises:
QueueEmpty – If no items are available and fewer items cannot be returned.
- Return type:
List[T]
Example
>>> tasks = await queue.get_multi(i=2, can_return_less=True) >>> print(tasks)
- get_multi_nowait(i, can_return_less=False)[source]
Retrieves up to i items from the queue without waiting.
- Parameters:
- Raises:
QueueEmpty – If no items are available and fewer items cannot be returned.
- Return type:
List[T]
Example
>>> tasks = queue.get_multi_nowait(i=3, can_return_less=True) >>> print(tasks)
- get_nowait()[source]
Retrieves and removes the next item from the queue without blocking.
This method does not wait for an item to be available and will raise an exception if the queue is empty.
- Raises:
QueueEmpty – If the queue is empty.
- Return type:
T
Example
>>> result = queue.get_nowait() >>> print(result)
- async join()[source]
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
- async put(item)[source]
Asynchronously adds an item to the queue.
If the queue is full, this method will block until space is available.
- Parameters:
item (T) – The item to add to the queue.
- Return type:
None
Example
>>> await queue.put(item='task')
- put_nowait(item)[source]
Adds an item to the queue without blocking.
This method does not wait for space to be available and will raise an exception if the queue is full.
- Parameters:
item (T) – The item to add to the queue.
- Raises:
QueueFull – If the queue is full.
- Return type:
None
Example
>>> queue.put_nowait(item='task')
- task_done()[source]
Indicate that a formerly enqueued task is complete.
Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises ValueError if called more times than there were items placed in the queue.
- _finished
- _getters
- _loop = None
- _maxsize
- _putters
- _queue
- _unfinished_tasks
- property maxsize
Number of items allowed in the queue.
- class a_sync.Semaphore
Bases:
_DebugDaemonMixin
Semaphore(int value: int = 1, name=None, loop=None, **kwargs) -> None
A semaphore with additional debugging capabilities inherited from
_DebugDaemonMixin
.This semaphore includes debug logging capabilities that are activated when the semaphore has waiters. It allows rewriting the pattern of acquiring a semaphore within a coroutine using a decorator.
Example
You can write this pattern:
``` semaphore = Semaphore(5)
- async def limited():
- async with semaphore:
return 1
like this:
``` semaphore = Semaphore(5)
@semaphore async def limited():
return 1
See also
_DebugDaemonMixin
for more details on debugging capabilities.- __call__()
Decorator method to wrap coroutine functions with the semaphore.
This allows rewriting the pattern of acquiring a semaphore within a coroutine using a decorator.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- __init__()
Initialize the semaphore with a given value and optional name for debugging.
- Parameters:
value – The initial value for the semaphore.
name (optional) – An optional name used only to provide useful context in debug logs.
- async _debug_daemon(self) None
Daemon coroutine (runs in a background task) which will emit a debug log every minute while the semaphore has waiters.
This method is part of the
_DebugDaemonMixin
and is used to provide detailed logging information about the semaphore’s state when it is being waited on.Example
semaphore = Semaphore(5)
- async def monitor():
await semaphore._debug_daemon()
- Return type:
None
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _wake_up_next(self) void
Wake up the first waiter that isn’t done.
- acquire(self)
Acquire the semaphore, ensuring that debug logging is enabled if there are waiters.
If the internal counter is larger than zero on entry, decrement it by one and return True immediately. If it is zero on entry, block, waiting until some other coroutine has called release() to make it larger than 0, and then return True.
If the semaphore value is zero or less, the debug daemon is started to log the state of the semaphore.
- Returns:
True when the semaphore is successfully acquired.
- decorate(self, fn: CoroFn[P, T]) CoroFn[P, T]
Wrap a coroutine function to ensure it runs with the semaphore.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- release(self) void
Release a semaphore, incrementing the internal counter by one.
When it was zero on entry and another coroutine is waiting for it to become larger than zero again, wake up that coroutine.
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _value
int
- Type:
Semaphore._value
- _waiters
int
- Type:
Semaphore._waiters
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- name
str
- Type:
Semaphore.name
- class a_sync.SmartProcessingQueue[source]
Bases:
_VariablePriorityQueueMixin
[T
],ProcessingQueue
[Concatenate
[T
,P
],V
]A processing queue that will execute jobs with the most waiters first, supporting dynamic priorities.
This queue is designed to handle tasks with dynamic priorities, ensuring that tasks with the most waiters are prioritized. It is ideal for scenarios where task execution order is influenced by the number of waiters.
Example
>>> async def process_task(data): return data.upper() >>> queue = SmartProcessingQueue(func=process_task, num_workers=5) >>> fut = await queue.put(item='task') >>> print(await fut) TASK
See also
- __call__(*args, **kwargs)
Submits a task to the queue.
Example
>>> fut = queue(*args, **kwargs) >>> print(fut)
- Parameters:
args (~P)
kwargs (~P)
- Return type:
Future[V]
- __init__(func, num_workers, *, name='', loop=None)[source]
Initializes a smart processing queue with the given worker function.
- Parameters:
func (Callable[[Concatenate[T, ~P]], Awaitable[V]]) – The worker function.
num_workers (int) – Number of worker tasks.
name (str) – Optional name for the queue.
loop (AbstractEventLoop | None) – Optional event loop.
- Return type:
None
Example
>>> queue = SmartProcessingQueue(func=my_task_func, num_workers=3, name='smart_queue')
- _ensure_workers()
Ensures that the worker tasks are running.
- Return type:
None
- _format()
- _get()[source]
Retrieves the task with the highest priority from the queue.
- Returns:
The priority, task arguments, keyword arguments, and future of the task.
Example
>>> task = queue._get() >>> print(task)
- _get_key(*args, **kwargs)
Generates a unique key for task identification based on arguments.
- Parameters:
args – Positional arguments for the task.
kwargs – Keyword arguments for the task.
- Returns:
The generated key for the task.
- Return type:
Example
>>> key = queue._get_key(*args, **kwargs) >>> print(key)
- _get_loop()
- _init(maxsize)
Initializes the priority queue.
Example
>>> queue._init(maxsize=10)
- _put(item, heappush=<built-in function heappush>)
Adds an item to the priority queue based on its priority.
Example
>>> queue._put(item='task')
- _wakeup_next(waiters)
- close()
Closes the queue, preventing further task submissions.
Example
>>> queue.close()
- Return type:
None
- empty()
Return True if the queue is empty, False otherwise.
- full()
Return True if there are maxsize items in the queue.
Note: if the Queue was initialized with maxsize=0 (the default), then full() is never True.
- async get()
Remove and return an item from the queue.
If queue is empty, wait until an item is available.
- get_nowait()
Remove and return an item from the queue.
Return an item if one is immediately available, else raise QueueEmpty.
- async join()
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
- async put(*args, **kwargs)[source]
Asynchronously adds a task with smart future handling to the queue.
- Parameters:
args (~P) – Positional arguments for the task.
kwargs (~P) – Keyword arguments for the task.
- Returns:
The future representing the task’s result.
- Return type:
SmartFuture[V]
Example
>>> fut = await queue.put(item='task') >>> print(await fut)
- put_nowait(*args, **kwargs)[source]
Immediately adds a task with smart future handling to the queue without waiting.
- Parameters:
args (~P) – Positional arguments for the task.
kwargs (~P) – Keyword arguments for the task.
- Returns:
The future representing the task’s result.
- Return type:
SmartFuture[V]
Example
>>> fut = queue.put_nowait(item='task') >>> print(await fut)
- qsize()
Number of items in the queue.
- task_done()
Indicate that a formerly enqueued task is complete.
Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises ValueError if called more times than there were items placed in the queue.
- _finished
- _futs: weakref.WeakValueDictionary[_smart._Key[T], _smart.SmartFuture[T]]
Weak reference dictionary for managing smart futures.
- _getters
- _loop = None
- _maxsize
- _name
Optional name for the queue.
- _no_futs = False
Whether smart futures are used.
- _putters
- _queue
- _unfinished_tasks
- _worker_coro
- func
The function that each worker will process.
- property maxsize
Number of items allowed in the queue.
- property name: str
Returns the name of the queue, or its representation.
Example
>>> print(queue.name)
- num_workers
The number of worker tasks for processing.
- class a_sync.TaskMapping[source]
Bases:
DefaultDict
[K
,asyncio.Task[V]
],AsyncIterable
[Tuple
[K
,V
]]A mapping of keys to asynchronous tasks with additional functionality.
TaskMapping is a specialized dictionary that maps keys to asyncio Tasks. It provides convenient methods for creating, managing, and iterating over these tasks asynchronously.
Tasks are created automatically for each key using a provided function. You cannot manually set items in a TaskMapping using dictionary-like syntax.
Example
>>> async def fetch_data(url: str) -> str: ... async with aiohttp.ClientSession() as session: ... async with session.get(url) as response: ... return await response.text() ... >>> tasks = TaskMapping(fetch_data, ['http://example.com', 'https://www.python.org'], name='url_fetcher', concurrency=5) >>> async for key, result in tasks: ... print(f"Data for {key}: {result}") ... Data for python.org: http://python.org Data for example.com: http://example.com
Note
You cannot manually set items in a TaskMapping using dictionary-like syntax. Tasks are created and managed internally.
- async __aiter__(pop=False)[source]
Asynchronously iterate through all key-task pairs, yielding the key-result pair as each task completes.
- Parameters:
pop (bool)
- Return type:
AsyncIterator[Tuple[K, V]]
- __init__(wrapped_func=None, *iterables, name='', concurrency=None, **wrapped_func_kwargs)[source]
Initialize a TaskMapping instance.
- Parameters:
wrapped_func (Callable[[Concatenate[K, ~P]], Awaitable[V]] | None) – A callable that takes a key and additional parameters and returns an Awaitable.
*iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]]) – Any number of iterables whose elements will be used as keys for task generation.
name (str) – An optional name for the tasks created by this mapping.
concurrency (int | None) – Maximum number of tasks to run concurrently.
**wrapped_func_kwargs (~P) – Additional keyword arguments to be passed to wrapped_func.
- Return type:
None
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item, [1, 2, 3], concurrency=2)
- __iter__()
Implement iter(self).
- _start_tasks_for_iterables(*iterables)[source]
Start new tasks for each key in the provided iterables.
- Parameters:
iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]])
- Return type:
AsyncIterator[Tuple[K, Task[V]]]
- _tasks_for_iterables(*iterables)[source]
Ensure tasks are running for each key in the provided iterables.
- Parameters:
iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]])
- Return type:
AsyncIterator[Tuple[K, Task[V]]]
- copy() a shallow copy of D.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingValues[K, V]
- keys() a set-like object providing a view on D's keys [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingKeys[K, V]
- map(*iterables, pop=True, yields='both')[source]
Asynchronously map iterables to tasks and yield their results.
- Parameters:
*iterables (AsyncIterable[K] | Iterable[K] | Awaitable[AsyncIterable[K] | Iterable[K]]) – Iterables to map over.
pop (bool) – Whether to remove tasks from the internal storage once they are completed.
yields (Literal['keys', 'both']) – Whether to yield ‘keys’, ‘values’, or ‘both’ (key-value pairs).
- Yields:
Depending on yields, either keys, values, or tuples of key-value pairs representing the results of completed tasks.
- Return type:
AsyncIterator[Tuple[K, V]]
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item) async for key, result in task_map.map([1, 2, 3]):
print(f”Processed {key}: {result}”)
- pop(*args, cancel=False)[source]
Pop a task from the TaskMapping.
- Parameters:
*args (K) – One key to pop.
cancel (bool) – Whether to cancel the task when popping it.
- Return type:
Task[V] | Future[V]
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values [source]
- Parameters:
pop (bool)
- Return type:
TaskMappingValues[K, V]
- yield_completed(pop=True)[source]
Asynchronously yield tuples of key-value pairs representing the results of any completed tasks.
- Parameters:
pop (bool) – Whether to remove tasks from the internal storage once they are completed.
- Yields:
Tuples of key-value pairs representing the results of completed tasks.
- Return type:
AsyncIterator[Tuple[K, V]]
Example
- async def process_item(item: int) -> int:
await asyncio.sleep(1) return item * 2
task_map = TaskMapping(process_item, [1, 2, 3]) async for key, result in task_map.yield_completed():
print(f”Completed {key}: {result}”)
- _destroyed: bool = False
Boolean indicating whether his mapping has been consumed and is no longer usable for aggregations.
- property _init_loader: Task[None] | None
An asyncio Task used to preload values from the iterables.
- _init_loader_next: Callable[[], Awaitable[Tuple[Tuple[K, Task[V]]]]] | None = None
A coro function that blocks until the _init_loader starts a new task(s), and then returns a Tuple[Tuple[K, asyncio.Task[V]]] with all of the new tasks and the keys that started them.
- _next: CythonEvent = None
An asyncio Event that indicates the next result is ready
- property _queue: ProcessingQueue
- _wrapped_func
The function used to create tasks for each key.
- default_factory
Factory for default value called by __missing__().
- a_sync.ThreadPoolExecutor
alias of
AsyncThreadPoolExecutor
- class a_sync.ThreadsafeSemaphore
Bases:
Semaphore
ThreadsafeSemaphore(value: Optional[int], name: Optional[str] = None) -> None
A semaphore that works in a multi-threaded environment.
This semaphore ensures that the program functions correctly even when used with multiple event loops. It provides a workaround for edge cases involving multiple threads and event loops by using a separate semaphore for each thread.
Example
semaphore = ThreadsafeSemaphore(5)
- async def limited():
- async with semaphore:
return 1
See also
Semaphore
for the base class implementation.- __call__()
Decorator method to wrap coroutine functions with the semaphore.
This allows rewriting the pattern of acquiring a semaphore within a coroutine using a decorator.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- __init__()
Initialize the threadsafe semaphore with a given value and optional name.
- Parameters:
value – The initial value for the semaphore, should be an integer.
name (optional) – An optional name for the semaphore.
- async _debug_daemon(self) None
Daemon coroutine (runs in a background task) which will emit a debug log every minute while the semaphore has waiters.
This method is part of the
_DebugDaemonMixin
and is used to provide detailed logging information about the semaphore’s state when it is being waited on.Example
semaphore = Semaphore(5)
- async def monitor():
await semaphore._debug_daemon()
- Return type:
None
- _ensure_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Ensures that the debug daemon task is running.
This method checks if the debug daemon is already running and starts it if necessary. If debug logging is not enabled, it sets the daemon to a dummy future.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
Either the debug daemon task or a dummy future if debug logging is not enabled.
- Return type:
Future[None]
Examples
Ensuring the debug daemon is running:
my_instance = MyDebugClass() my_instance._ensure_debug_daemon()
See also
_start_debug_daemon()
for starting the daemon.
- _get_loop(self)
- _start_debug_daemon(self, *args, **kwargs) 'asyncio.Future[None]'
Starts the debug daemon task if debug logging is enabled and the event loop is running.
This method checks if debug logging is enabled and if the event loop is running. If both conditions are met, it starts the debug daemon task.
- Parameters:
*args – Positional arguments for the debug daemon.
**kwargs – Keyword arguments for the debug daemon.
- Returns:
The debug daemon task as an asyncio.Task, or a dummy future if debug logs are not enabled or if the daemon cannot be created.
- Return type:
Future[None]
Examples
Starting the debug daemon:
my_instance = MyDebugClass() my_instance._start_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _stop_debug_daemon(self, t: asyncio.Task | None = None) None
Stops the debug daemon task.
This method cancels the debug daemon task if it is running. Raises a ValueError if the task to be stopped is not the current daemon.
- Parameters:
t (optional) – The task to be stopped, if any.
- Raises:
ValueError – If t is not the current daemon.
- Return type:
None
Examples
Stopping the debug daemon:
my_instance = MyDebugClass() my_instance._stop_debug_daemon()
See also
_ensure_debug_daemon()
for ensuring the daemon is running.
- _wake_up_next(self) void
Wake up the first waiter that isn’t done.
- acquire(self)
Acquire the semaphore, ensuring that debug logging is enabled if there are waiters.
If the internal counter is larger than zero on entry, decrement it by one and return True immediately. If it is zero on entry, block, waiting until some other coroutine has called release() to make it larger than 0, and then return True.
If the semaphore value is zero or less, the debug daemon is started to log the state of the semaphore.
- Returns:
True when the semaphore is successfully acquired.
- decorate(self, fn: CoroFn[P, T]) CoroFn[P, T]
Wrap a coroutine function to ensure it runs with the semaphore.
Example
semaphore = Semaphore(5)
@semaphore async def limited():
return 1
- release(self) void
Release a semaphore, incrementing the internal counter by one.
When it was zero on entry and another coroutine is waiting for it to become larger than zero again, wake up that coroutine.
- _loop
asyncio.AbstractEventLoop
- Type:
_LoopBoundMixin._loop
- _value
int
- Type:
Semaphore._value
- _waiters
int
- Type:
Semaphore._waiters
- debug_logs_enabled
bool
Checks if debug logging is enabled for the logger.
Examples
>>> class MyClass(_LoggerMixin): ... pass ... >>> instance = MyClass() >>> instance.debug_logs_enabled False
See also
- Type:
_LoggerMixin.debug_logs_enabled
- logger
Logger
Provides a logger instance specific to the class using this mixin.
The logger ID is constructed from the module and class name, and optionally includes an instance name if available.
Examples
>>> class MyClass(_LoggerMixin): ... _name = "example" ... >>> instance = MyClass() >>> logger = instance.logger >>> logger.name 'module_name.MyClass.example'
>>> class AnotherClass(_LoggerMixin): ... pass ... >>> another_instance = AnotherClass() >>> another_logger = another_instance.logger >>> another_logger.name 'module_name.AnotherClass'
Note
Replace module_name with the actual module name where the class is defined.
See also
- Type:
_LoggerMixin.logger
- name
str
- Type:
Semaphore.name
- semaphore
Semaphore
Returns the appropriate semaphore for the current thread.
NOTE: We can’t cache this property because we need to check the current thread every time we access it.
Example
semaphore = ThreadsafeSemaphore(5)
- async def limited():
- async with semaphore.semaphore:
return 1
- Type:
ThreadsafeSemaphore.semaphore
- class a_sync.cached_property
Bases:
ASyncCachedPropertyDescriptor
[I
,T
]Descriptor for defining cached properties that can be accessed both synchronously and asynchronously.
- __init__(self, _fget: AsyncGetterFunction[I, T], _fset=None, _fdel=None, field_name=None, **modifiers: Unpack[ModifierKwargs]) None
Initializes the ASyncCachedPropertyDescriptor.
- Parameters:
_fget (Callable[[I], Awaitable[T]]) – The function to be wrapped.
_fset – Optional setter function for the property.
_fdel – Optional deleter function for the property.
field_name – Optional name for the field. If not provided, the function’s name will be used.
**modifiers (Unpack[ModifierKwargs]) – Additional modifier arguments.
- Return type:
None
- async _all(*instances, concurrency=None, name='', **kwargs)
Check if all results are truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._all([1, 2, 3]) ```
- async _any(*instances, concurrency=None, name='', **kwargs)
Check if any result is truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._any([-1, 0, 1]) ```
- _asyncify(self, func: SyncFn[P, T]) CoroFn[P, T]
Converts a synchronous function to an asynchronous one and applies async modifiers.
- Parameters:
func (Callable[[~P], T]) – The synchronous function to be converted.
- Returns:
The asynchronous version of the function with applied modifiers.
- Return type:
See also
ModifierManager.apply_async_modifiers()
- _check_method_name(method, method_type)
- _check_method_sync(method, method_type)
- async _max(*instances, concurrency=None, name='', **kwargs)
Find the maximum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._max([3, 1, 2]) ```
- async _min(*instances, concurrency=None, name='', **kwargs)
Find the minimum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._min([3, 1, 2]) ```
- async _sum(*instances, concurrency=None, name='', **kwargs)
Calculate the sum of results.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._sum([1, 2, 3]) ```
- already_loaded(instance)
- del_cache_value(instance)
- deleter(method)
- async get(self, instance: I, owner: Type[I] | None = None) T
Asynchronously retrieves the property value.
- get_cache(instance)
- get_cache_value(instance)
- get_instance_state(instance)
- get_lock(self, instance: I) 'asyncio.Task[T]'
Retrieves the lock for the property.
- Parameters:
instance (I) – The instance from which the property is accessed.
- Returns:
An asyncio Task representing the lock.
- Return type:
Task[T]
- has_cache_value(instance)
- map(self, instances: AnyIterable[I], owner: Optional[Type[I]] = None, concurrency: Optional[int] = None, unicode name: str = u'') 'TaskMapping[I, T]'
Maps the property across multiple instances.
- not_loaded(instance)
- pop_lock(self, instance: I) None
Removes the lock for the property.
- Parameters:
instance (I) – The instance from which the property is accessed.
- Return type:
None
- set_cache_value(instance, value)
- setter(method)
- property _TaskMapping: Type[TaskMapping]
This silly helper just fixes a circular import
- property _await: Callable[[Awaitable[T]], T]
Applies sync modifiers to the _helpers._await function and caches it.
- Returns:
The modified _await function.
See also
ModifierManager.apply_sync_modifiers()
- property all: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if all results are truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.all([1, 2, 3])
- property any: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if any result is truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.any([-1, 0, 1])
- property default: Literal['sync', 'async', None]
Gets the default execution mode (sync, async, or None) for the function.
- Returns:
The default execution mode.
See also
ModifierManager.default
- field_name
The name of the field the
ASyncDescriptor
is bound to.
- property max: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the maximum result.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.max([3, 1, 2])
- property min: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the minimum result.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.min([3, 1, 2]) ```
- modifiers
- property sum: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the sum of results.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.sum([1, 2, 3]) ```
- wrapped
- a_sync.filter
alias of
ASyncFilter
- a_sync.map
alias of
TaskMapping
- class a_sync.property
Bases:
ASyncPropertyDescriptor
[I
,T
]Descriptor for defining properties that can be accessed both synchronously and asynchronously.
- __init__(self, _fget: AsyncGetterFunction[I, T], field_name: str | None = None, **modifiers: Unpack[ModifierKwargs]) None
Initializes the _ASyncPropertyDescriptorBase.
- Parameters:
_fget (Callable[[I], Awaitable[T]]) – The function to be wrapped.
field_name (str | None) – Optional name for the field. If not provided, the function’s name will be used.
**modifiers (Unpack[ModifierKwargs]) – Additional modifier arguments.
- Return type:
None
- async _all(*instances, concurrency=None, name='', **kwargs)
Check if all results are truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._all([1, 2, 3]) ```
- async _any(*instances, concurrency=None, name='', **kwargs)
Check if any result is truthy.
- Parameters:
- Return type:
Examples
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method._any([-1, 0, 1]) ```
- _asyncify(self, func: SyncFn[P, T]) CoroFn[P, T]
Converts a synchronous function to an asynchronous one and applies async modifiers.
- Parameters:
func (Callable[[~P], T]) – The synchronous function to be converted.
- Returns:
The asynchronous version of the function with applied modifiers.
- Return type:
See also
ModifierManager.apply_async_modifiers()
- async _max(*instances, concurrency=None, name='', **kwargs)
Find the maximum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._max([3, 1, 2]) ```
- async _min(*instances, concurrency=None, name='', **kwargs)
Find the minimum result.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._min([3, 1, 2]) ```
- async _sum(*instances, concurrency=None, name='', **kwargs)
Calculate the sum of results.
- Parameters:
- Return type:
T
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method._sum([1, 2, 3]) ```
- awaitable_only(instance)
- async get(self, instance: I, owner: Type[I] | None = None) T
Asynchronously retrieves the property value.
- get_loader(instance)
- map(self, instances: AnyIterable[I], owner: Optional[Type[I]] = None, concurrency: Optional[int] = None, unicode name: str = u'') 'TaskMapping[I, T]'
Maps the property across multiple instances.
- property _TaskMapping: Type[TaskMapping]
This silly helper just fixes a circular import
- property _await: Callable[[Awaitable[T]], T]
Applies sync modifiers to the _helpers._await function and caches it.
- Returns:
The modified _await function.
See also
ModifierManager.apply_sync_modifiers()
- property all: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if all results are truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.all([1, 2, 3])
- property any: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], bool]
Create an
ASyncFunction
that checks if any result is truthy.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x > 0
instance = MyClass() result = await instance.my_method.any([-1, 0, 1])
- property default: Literal['sync', 'async', None]
Gets the default execution mode (sync, async, or None) for the function.
- Returns:
The default execution mode.
See also
ModifierManager.default
- field_name
The name of the field the
ASyncDescriptor
is bound to.
- property max: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the maximum result.- Returns:
An
ASyncFunction
object.
Examples
- class MyClass:
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.max([3, 1, 2])
- property min: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the minimum result.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.min([3, 1, 2]) ```
- modifiers
- property sum: ASyncFunction[Concatenate[AsyncIterable[I] | Iterable[I], P], T]
Create an
ASyncFunction
that returns the sum of results.- Returns:
An
ASyncFunction
object.
Examples
@ASyncDescriptor def my_method(self, x):
return x
instance = MyClass() result = await instance.my_method.sum([1, 2, 3]) ```
- wrapped
- a_sync.sorted
alias of
ASyncSorter
- a_sync.a_sync(coro_fn=None, default=None, **modifiers)[source]
A versatile decorator that enables both synchronous and asynchronous execution of functions.
This decorator allows a function to be called either synchronously or asynchronously, depending on the context and parameters. It provides a powerful way to write code that can be used in both synchronous and asynchronous environments.
- Parameters:
coro_fn (Callable[[~P], Awaitable[T]] | Callable[[~P], T] | None) – The function to be decorated. Can be either a coroutine function or a regular function.
default (Literal['sync', 'async', None] | None) – Determines the default execution mode. Can be ‘async’, ‘sync’, or None. If None, the mode is inferred from the decorated function type.
**modifiers (Unpack[ModifierKwargs]) – Additional keyword arguments to modify the behavior of the decorated function. See
ModifierKwargs
for available options.
- Return type:
ASyncDecorator | ASyncFunction[~P, T]
- Modifiers:
The following modifiers can be used to customize the behavior of the decorator:
cache_type: Can be None or ‘memory’. ‘memory’ is an LRU cache which can be modified with the ‘cache_typed’, ‘ram_cache_maxsize’, and ‘ram_cache_ttl’ modifiers.
cache_typed: Set to True if you want types considered for cache keys. For example, with cache_typed=True, Decimal(0) and 0 will be considered separate keys.
ram_cache_maxsize: The max size for your LRU cache. None if the cache is unbounded. If you set this value without specifying a cache type, ‘memory’ will automatically be applied.
ram_cache_ttl: The TTL for items in your LRU cache. Set to None. If you set this value without specifying a cache type, ‘memory’ will automatically be applied.
runs_per_minute: Setting this value enables a rate limiter for the decorated function.
semaphore: Drop in a Semaphore for your async defined functions.
executor: The executor for the synchronous function. Set to the library’s default of config.default_sync_executor.
Examples
The decorator can be used in several ways.
- As a simple decorator:
>>> @a_sync ... async def some_async_fn(): ... return True >>> await some_async_fn() True >>> some_async_fn(sync=True) True
>>> @a_sync ... def some_sync_fn(): ... return True >>> some_sync_fn() True >>> some_sync_fn(sync=False) <coroutine object some_sync_fn at 0x7fb4f5fb49c0>
- As a decorator with default mode specified:
>>> @a_sync(default='sync') ... async def some_fn(): ... return True ... >>> some_fn() True >>> some_fn(sync=False) <coroutine object some_fn at 0x7fb4f5fb49c0>
>>> @a_sync('async') ... def some_fn(): ... return True ... >>> some_fn() <coroutine object some_fn at 0x7fb4f5fb49c0> >>> some_fn(asynchronous=False) True
- As a decorator with modifiers:
>>> @a_sync(cache_type='memory', runs_per_minute=60) ... async def some_fn(): ... return True ... >>> some_fn(sync=True) True
- Applied directly to a function:
>>> some_fn = a_sync(some_existing_function, default='sync') >>> some_fn() "some return value"
- The decorated function can then be called either synchronously or asynchronously:
>>> result = some_fn() # Synchronous call >>> result = await some_fn() # Asynchronous call
- The execution mode can also be explicitly specified during the call:
>>> result = some_fn(sync=True) # Force synchronous execution >>> result = await some_fn(sync=False) # Force asynchronous execution
This decorator is particularly useful for libraries that need to support both synchronous and asynchronous usage, or for gradually migrating synchronous code to asynchronous without breaking existing interfaces.
Note
If the coro_fn argument is passed as ‘async’ or ‘sync’, it is treated as the default argument, and coro_fn is set to None.
See also
ASyncFunction
,ASyncDecorator
- async a_sync.all(*awaitables)[source]
Asynchronously evaluates whether all of the given awaitables evaluate to True.
This function takes multiple awaitable objects and returns True if all of them evaluate to True. It cancels the remaining awaitables once a False result is found.
- Parameters:
*awaitables – A variable length list of awaitable objects.
- Returns:
True if all elements are truthy or the iterable is empty, False otherwise.
- Return type:
Example
>>> async def is_even(x): ... return x % 2 == 0 ... >>> numbers = [2, 4, 6, 8] >>> result = await all(*[is_even(x) for x in numbers]) >>> result True >>> numbers = [2, 3, 4, 6] >>> result = await all(*[is_even(x) for x in numbers]) >>> result False
- async a_sync.any(*awaitables)[source]
Asynchronously evaluates whether any of the given awaitables evaluates to True.
This function returns True if any element in the asynchronous iterable is truthy. It short-circuits on the first truthy value. If the iterable is empty, it returns False.
- Parameters:
*awaitables – A variable length list of awaitable objects.
- Returns:
True if any element is truthy, False if all are falsy or the iterable is empty.
- Return type:
Example
>>> async def is_odd(x): ... await asyncio.sleep(0.1) # Simulate some async work ... return x % 2 != 0 ... >>> numbers = [2, 4, 6, 7] >>> result = await any(*[is_odd(x) for x in numbers]) >>> result True >>> numbers = [2, 4, 6, 8] >>> result = await any(*[is_odd(x) for x in numbers]) >>> result False
Note
This function will stop iterating as soon as it encounters a truthy value.
- a_sync.as_completed(fs, *, timeout: float | None = None, return_exceptions: bool = False, aiter: bool = False, tqdm: bool = False, **tqdm_kwargs: Any)
Concurrently awaits a list of awaitable objects or mappings of awaitables and returns an iterator of results.
This function extends Python’s
asyncio.as_completed()
, providing additional features for mixed use cases of individual awaitable objects and mappings of awaitables.Differences from
asyncio.as_completed()
: - Uses type hints for use with static type checkers. - Supports either individual awaitables or a k:v mapping of awaitables. - Can be used as an async iterator which yields the result values usingASyncIterator
. - Provides progress reporting usingtqdm
if ‘tqdm’ is set to True.Note
The return_exceptions parameter is used to wrap awaitables with exceptions if set to True, allowing exceptions to be returned as results instead of being raised.
- Parameters:
fs – The awaitables to await concurrently. It can be a list of individual awaitables or a mapping of awaitables.
timeout (float | None) – The maximum time, in seconds, to wait for the completion of awaitables. Defaults to None (no timeout).
return_exceptions (bool) – If True, exceptions are wrapped and returned as results instead of raising them. Defaults to False.
aiter (bool) – If True, returns an async iterator of results using
ASyncIterator
. Defaults to False.tqdm (bool) – If True, enables progress reporting using
tqdm
. Defaults to False.**tqdm_kwargs (Any) – Additional keyword arguments for
tqdm
if progress reporting is enabled.
Examples
Awaiting individual awaitables:
>>> awaitables = [async_function1(), async_function2()] >>> for coro in as_completed(awaitables): ... val = await coro ... ...
>>> async for val in as_completed(awaitables, aiter=True): ... ...
Awaiting mappings of awaitables:
>>> mapping = {'key1': async_function1(), 'key2': async_function2()} >>> for coro in as_completed(mapping): ... k, v = await coro ... ...
>>> async for k, v in as_completed(mapping, aiter=True): ... ...
See also
- async a_sync.as_yielded(*iterators)[source]
Merges multiple async iterators into a single async iterator that yields items as they become available from any of the source iterators.
This function is designed to streamline the handling of multiple asynchronous data streams by consolidating them into a single asynchronous iteration context. It enables concurrent fetching and processing of items from multiple sources, improving efficiency and simplifying code structure when dealing with asynchronous operations.
The merging process is facilitated by the
exhaust_iterators()
function, which concurrently processes the source iterators and places their items into a queue. This mechanism ensures that the merged stream of items is delivered in an order determined by the availability of items from the source iterators, rather than their original sequence.The function handles exceptions and ensures robustness and reliability by using asyncio tasks and queues. It manages edge cases such as early termination and exception management. The
_Done
sentinel class is used internally to signal the completion of processing.- Parameters:
*iterators (AsyncIterator[T]) – Variable length list of
AsyncIterator
objects to be merged.- Return type:
Note
This implementation leverages asyncio tasks and queues to efficiently manage the asynchronous iteration and merging process. It handles edge cases such as early termination and exception management, ensuring robustness and reliability. The
_Done
sentinel class is used internally to signal the completion of processing.Example
>>> async def example(): >>> async for item in as_yielded(iterator1, iterator2): >>> print(item)
See also
exhaust_iterator()
exhaust_iterators()
- a_sync.create_task(coro: Awaitable[T], *, unicode name: str = u'', skip_gc_until_done: bint = False, log_destroy_pending: bint = True) 'asyncio.Task[T]'
Extends
asyncio.create_task()
to support anyAwaitable
, manage task lifecycle, and enhance error handling.This function accepts any
Awaitable
, ensuring broader compatibility. If the Awaitable is not a coroutine, it is awaited directly using a private helper function __await, which can handle non-coroutine Awaitable objects.Note
The __await function is designed to handle non-coroutine Awaitables by awaiting them directly.
- Parameters:
coro (Awaitable[T]) – An
Awaitable
object from which to create the task.name (str) – Optional name for the task, aiding in debugging.
skip_gc_until_done (bint) – If True, the task is kept alive until it completes, preventing garbage collection. Exceptions are wrapped in
PersistedTaskException
for special handling within the __persisted_task_exc_wrap function.log_destroy_pending (bint) – If False, asyncio’s default error log when a pending task is destroyed is suppressed.
- Return type:
asyncio.Task[T]
Examples
Create a simple task with a coroutine:
>>> async def my_coroutine(): ... return "Hello, World!" >>> task = create_task(my_coroutine())
Create a task with a non-coroutine Awaitable:
>>> from concurrent.futures import Future >>> future = Future() >>> task = create_task(future)
See also
- async a_sync.gather(*awaitables: Awaitable[T] | Mapping[K, Awaitable[V]], return_exceptions: bool = False, exclude_if: Excluder[T] | None = None, tqdm: bool = False, **tqdm_kwargs: Any) List[T] | Dict[K, V]
Concurrently awaits a list of awaitable objects or a k:v mapping of awaitables, and returns the results.
This function extends Python’s
asyncio.gather()
, providing additional features for handling either individual awaitable objects or a single mapping of awaitables.Differences from
asyncio.gather()
: - Uses type hints for use with static type checkers. - Supports gathering either individual awaitables or a k:v mapping of awaitables. - Provides progress reporting using tqdm if ‘tqdm’ is set to True. - Allows exclusion of results based on a condition using the ‘exclude_if’ parameter. Note: This is only applied when the input is not a mapping.- Parameters:
*awaitables (Awaitable[T] | Mapping[K, Awaitable[V]]) – The awaitables to await concurrently. It can be a list of individual awaitables or a single mapping of awaitables.
return_exceptions (bool, optional) – If True, exceptions are returned as results instead of raising them. Defaults to False.
exclude_if (Optional[Excluder[T]], optional) – A callable that takes a result and returns True if the result should be excluded from the final output. Defaults to None. Note: This is only applied when the input is not a mapping.
tqdm (bool, optional) – If True, enables progress reporting using tqdm. Defaults to False.
**tqdm_kwargs – Additional keyword arguments for tqdm if progress reporting is enabled.
- Return type:
Examples
Awaiting individual awaitables:
>>> results = await gather(thing1(), thing2()) >>> results ['result', 123]
Awaiting a mapping of awaitables:
>>> mapping = {'key1': thing1(), 'key2': thing2()} >>> results = await gather(mapping) >>> results {'key1': 'result', 'key2': 123}
See also