Skip to content

Commit

Permalink
- Lock multithreading for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Feb 28, 2023
1 parent 018131d commit 86683ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dizqueTV/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Internal Helpers
def _multithread(
func, elements: List, element_param_name: str, thread_count: int = 20, **kwargs
func, elements: List, element_param_name: str, thread_count: int = None, **kwargs
) -> List:
"""
Multithread a function for elements in a list
Expand All @@ -39,6 +39,11 @@ def _multithread(
:return: List of results from the function
:rtype: list
"""
# Thread count is the smallest of the following:
# - Number of elements in the list
# - Number of CPU cores * 8 (arbitrary)
# Or override with thread_count
thread_count = thread_count or min(len(element_param_name), (os.cpu_count() * 8))
thread_list = []
pool = ThreadPoolExecutor(thread_count)

Expand Down

0 comments on commit 86683ff

Please sign in to comment.