Intuitive Rust-based channel concurrency using the actor/handle pattern
Install
$ pip install fechan
About
The fechan package ("Fe" = Iron = Rust + "chan" = channels) was designed to be intuitive. The fact that it is written in Rust does give it a measurable performance boost, it is ~1.5x faster than Python's built-in threading + queue libraries, but at the end of the day OS threads perform (more or less) the same regardless of the laguage used to spawn them.
The real benefit to using fechan comes from its intuitive API. All of the manual queue.Queue() / threading.Thread() / thread.join() operations required with Python's built-in threading + queue libraries are replaced by a simple "send + close + collect" pattern in fechan.
That's it, that's the whole API.
Example
Consider a typical Python concurrency workflow using Python's threading + queue libraries:
import threading
import queue
def some_cpu_or_io_func(x):
"""
Some placeholder function for CPU bound / IO bound work
"""
return x * x
def thread_worker(fn, args, q):
try:
q.put(fn(*args))
except Exception as e:
q.put(str(e))
queue_results = queue.Queue()
threads = []
for i in range(100):
t = threading.Thread(target = thread_worker, args = (some_cpu_or_io_func, (i, ), queue_results))
t.start()
threads.append(t)
for t in threads:
t.join()
results = [queue_results.get() for _ in range(100)]
We can compare that to the much more concise fechan workflow:
from fechan import create_channel
def some_cpu_or_io_func(x):
"""
A placeholder function for CPU bound / IO bound work
"""
return x * x
# The entire "send + close + collect" API:
actor, handle = create_channel()
for i in range(100):
handle.send(some_cpu_or_io_func, (i, ))
handle.close()
results = actor.collect_results()
Roadmap
Work in progress...
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fechan-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: fechan-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 520.5 kB
- Tags: CPython 3.12, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c946db51dbd216edf5a82f13162bfdd42cb8611a3132cb217a2ecd2e9ad693
|
|
| MD5 |
6781fd6df06763498d65e2a6a0376939
|
|
| BLAKE2b-256 |
24b644bf0b8a0a414bfabf3a8db2c847d584cd5b246a2c4f2339b423da2d1e15
|