snowflake.snowpark.functions.udf_init_once¶
- snowflake.snowpark.functions.udf_init_once(func: Callable) Callable[source]¶
Mark a function to be executed once during pre-fork initialization.
This decorator has the same signature as the server-side
_snowflake.udf_init_once. It is a no-op for local invocation. Functions decorated with@udf_init_oncerun in the head worker process before individual workers are forked. The initialized state (e.g., loaded models, computed lookup tables) is shared across all workers via Copy-On-Write.- The decorated function must:
Accept zero arguments
Be a callable (function, lambda, or callable object)
Multiple
@udf_init_oncefunctions are executed in the order they are defined.Example:
Use this decorator in handler files registered via
register_from_file(). On the Snowflake server the_snowflake.udf_init_onceimplementation is used instead; this client-side definition provides the same API so that handler files can be tested locally.- Parameters:
func – The init function to decorate. Must be callable and accept zero arguments.
- Returns:
The decorated function, unchanged.
See also