Skip to main content

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

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.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (520.5 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.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for fechan-0.1.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e7c946db51dbd216edf5a82f13162bfdd42cb8611a3132cb217a2ecd2e9ad693
MD5 6781fd6df06763498d65e2a6a0376939
BLAKE2b-256 24b644bf0b8a0a414bfabf3a8db2c847d584cd5b246a2c4f2339b423da2d1e15

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

1 file

This release

0.1.1 This release

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