Reference for hub_sdk/helpers/utils.py
Note
This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/helpers/utils.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
hub_sdk.helpers.utils.threaded
Multi-threads a target function by default and returns the thread or function result.
This decorator provides flexible execution of the target function, either in a separate thread or synchronously. By default, the function runs in a thread, but this can be controlled via the 'threaded=False' keyword argument which is removed from kwargs before calling the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
The function to be potentially executed in a separate thread. |
required |
Returns:
Type | Description |
---|---|
callable
|
A wrapper function that either returns a daemon thread or the direct function result. |
Examples:
>>> @threaded
... def process_data(data):
... return data
>>>
>>> thread = process_data(my_data) # Runs in background thread
>>> result = process_data(my_data, threaded=False) # Runs synchronously, returns function result
Source code in hub_sdk/helpers/utils.py
📅 Created 1 year ago
✏️ Updated 1 month ago