osbot-utils 2.43.0__py3-none-any.whl → 2.45.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,13 +42,34 @@ def invoke_in_new_event_loop(target: typing.Coroutine): # Runs a cor
42
42
  result = future.result() # Wait for the result of the future
43
43
  return result # Return the result from the coroutine
44
44
 
45
- async def async__execute_coroutines(coroutines, return_exceptions: bool = False) -> list: # """ Execute multiple coroutines concurrently and wait for all to complete.
46
- return await asyncio.gather(*coroutines, return_exceptions=return_exceptions)
45
+ from concurrent.futures import ThreadPoolExecutor
46
+ from typing import Callable, List, TypeVar, Any, Optional
47
+
48
+ T = TypeVar('T') # Type of items in the list
49
+ R = TypeVar('R') # Return type of the function
50
+
51
+ def execute_in_thread_pool(target_function : Callable[[T], R] , # Function to execute
52
+ items : List[Any] , # Items to process
53
+ max_workers : Optional[int] = None , # Maximum worker threads
54
+ return_exceptions: bool = False # Return rather than raise exceptions
55
+ ) -> List[R]: # List of results
56
+ """Execute a function for each item in parallel using ThreadPoolExecutor."""
47
57
 
48
- def invoke_async__coroutines(coroutines, return_exceptions: bool = False) -> list:
49
- return invoke_async_function(async__execute_coroutines(coroutines, return_exceptions))
58
+ args_list = [(item,) for item in items] # Convert list of items to list of single-item tuples (so that we support one or more params)
59
+ results = []
60
+ with ThreadPoolExecutor(max_workers=max_workers) as executor:
50
61
 
62
+ futures = [executor.submit(target_function, *args) for args in args_list] # Submit all tasks to the executor
51
63
 
64
+ for future in futures: # Wait for all to complete and collect results
65
+ try:
66
+ results.append(future.result())
67
+ except Exception as e:
68
+ if return_exceptions:
69
+ results.append(e)
70
+ else:
71
+ raise
72
+ return results
52
73
 
53
74
  # in the use cases when I tried to use this, it hanged
54
75
  # def invoke_in_current_loop(target: typing.Coroutine):
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.43.0
1
+ v2.45.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.43.0
3
+ Version: 2.45.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  License: MIT
6
6
  Author: Dinis Cruz
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  Powerful Python util methods and classes that simplify common apis and tasks.
25
25
 
26
- ![Current Release](https://img.shields.io/badge/release-v2.43.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.45.0-blue)
27
27
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
28
28
 
29
29
 
@@ -393,13 +393,13 @@ osbot_utils/utils/Python_Logger.py,sha256=M9Oi62LxfnRSlCN8GhaiwiBINvcSdGy39FCWjy
393
393
  osbot_utils/utils/Regex.py,sha256=MtHhk69ax7Nwu4CQZK7y4KXHZ6VREwEpIchuioB168c,960
394
394
  osbot_utils/utils/Status.py,sha256=OjqLwUhHqY-j-JeRN-hIaVZQHPRdyjR7y6i6ujsB-Yc,4287
395
395
  osbot_utils/utils/Str.py,sha256=KQVfh0o3BxJKVm24yhAhgIGH5QYfzpP1G-siVv2zQws,3301
396
- osbot_utils/utils/Threads.py,sha256=gXd26uPy5tJ2Bb3hdwaEr3KctaZUQR9mmVYbrrhhPig,3506
396
+ osbot_utils/utils/Threads.py,sha256=xteAkZ8GnZAhD2tPkcplLWXquAr9Ix5EA1PDWPVPruo,4560
397
397
  osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,1667
398
398
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
399
399
  osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
400
400
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
401
- osbot_utils/version,sha256=RQOQkvelJmKVw3XhrLjS20nIAlx7S5yhqSlwTzgxbQE,8
402
- osbot_utils-2.43.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
403
- osbot_utils-2.43.0.dist-info/METADATA,sha256=cqzo9kHZYU6x6JDimXZXL1hwn49k4m1WPwGgiw2phyE,1329
404
- osbot_utils-2.43.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
405
- osbot_utils-2.43.0.dist-info/RECORD,,
401
+ osbot_utils/version,sha256=dbkG2N0zIZpi__26uQkTT25J_7MRPnslQNbuuRwCr5k,8
402
+ osbot_utils-2.45.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
403
+ osbot_utils-2.45.0.dist-info/METADATA,sha256=Ux6oooT44TTYI3OGmovfcYckgtrGQupGVABeEZEZwRY,1329
404
+ osbot_utils-2.45.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
405
+ osbot_utils-2.45.0.dist-info/RECORD,,