Skip to main content

Intuitive Rust-based channel concurrency using the actor/handle pattern




Compatibility

OS Works Notes
MacOS Tested works
Linux ⚠️ WIP - Might release it as a standalone package?
Windows Feel free to fork & build it yourself. I never will.



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()

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fechan-0.2.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (520.3 kB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file fechan-0.2.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for fechan-0.2.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 137273b0815cc78dbe623e2ca1cc4a46e1dd438640e4855b9873eb026f01e4a2
MD5 6028822aca0cf9a791290f8bcb624263
BLAKE2b-256 eaa8aee2c034fe9c76179efc55b9371f1c8fa45ed96122eb856387e35503a7bb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 file

0.1.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page