Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shahaf-f-s/multithreading
A python module for creating multithreading processes easily, in a more Pythonic way.
https://github.com/shahaf-f-s/multithreading
functional-programming multi-threading multithreading threading
Last synced: 6 days ago
JSON representation
A python module for creating multithreading processes easily, in a more Pythonic way.
- Host: GitHub
- URL: https://github.com/shahaf-f-s/multithreading
- Owner: Shahaf-F-S
- Created: 2023-06-17T10:14:15.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-19T15:55:19.000Z (7 months ago)
- Last Synced: 2024-11-09T08:19:20.537Z (7 days ago)
- Topics: functional-programming, multi-threading, multithreading, threading
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multithreading
> A python module for creating multithreading processes easily, in a more Pythonic way.
## Installation
```
pip install python-multithreading
```## example
```python
import timefrom multithreading import Caller, multi_threaded_call
def slow_function(number: int, delay: float) -> dict[str, int | float]:
for i in range(number):
time.sleep(delay)return dict(number=number, delay=delay)
CALLS = 50
DELAY = 0.01
NUMBER = 100callers = [
Caller(
target=slow_function,
kwargs=dict(delay=DELAY, number=NUMBER)
) for _ in range(CALLS)
]s = time.time()
multi_threaded_call(callers)
e = time.time()
print("multi-threading: ", e - s)
s = e
all(slow_function(*caller.args, **caller.kwargs) for caller in callers)
e = time.time()
print("single-threading: ", e - s)
```output
```
multi-threading: 1.0473840236663818
single-threading: 52.53497314453125
```