https://github.com/chillfish8/tactix
A work-stealing actor framework for Python built on Tokio.rs
https://github.com/chillfish8/tactix
Last synced: 2 months ago
JSON representation
A work-stealing actor framework for Python built on Tokio.rs
- Host: GitHub
- URL: https://github.com/chillfish8/tactix
- Owner: ChillFish8
- Created: 2021-01-06T13:57:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-06T17:24:56.000Z (over 4 years ago)
- Last Synced: 2025-02-01T14:32:06.864Z (4 months ago)
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tactix
A work-stealing actor framework for Python built on Tokio.rs.The easiest way to understand how Tactix works is think:
#### asyncio + threading + actors => tactixUnlike asyncio tactix will not be stopped or be interrupted by blocking tasks,
instead if a particular worker thread is blocking the other threads will steal
the work off of the blocked thread until it is released again.This does mean you can use regular blocking calls like time.sleep(n) and not
fear blocking the whole loop but note this will still affect the loop if more
than `n` blocking tasks are running where `n` is the amount of logical CPU cores.## Example
```py
from time import sleepimport tactix
from tactix import Actor, ActorContextclass MyActor(Actor):
def __init__(self):
super().__init__()@Actor.listener()
def on_foo(self, message):
self.handle_foo(message)@Actor.wrap_coroutine
async def handle_foo(self, ctx: ActorContext, message):
# Like asyncio, using a non-blocking sleep, thousands of
# tasks can run on a single thread.
await ctx.sleep(message[1])
print("done!")@Actor.listener(name="on_hello")
def custom_name(self, message):
# Now this will block the worker but all other tasks will be
# un-effected as the work stealer will have re-distributed tasks.
sleep(2)
print(f"Got: {message}")def main():
act1 = MyActor()
act1.send("foo", ("foo 1", 5), delay=2)
act1.send("hello", "Hello, World!")sleep(8)
if __name__ == '__main__':
tactix.run(main)
```## Building
Obviously because this system is built of the Rust back bone you're going to need
to install Rust, you will also need `cmake`.### Using Maturin:
1) `git pull https://github.com/ChillFish8/tactix.git`
2) `maturin develop` or `maturin develop --release`
3) Have fun.