PyWorks - a small concurrent framework for Python
Ever since i first worked with threads in Java 15 years ago, I have been
struggeling with the concept. Before that I was used to C and a homegrown "OS"
called Daros. It had Task "preemtive processes", Messages and Queues. For me
it was much easier to comprehend the one Task == one thread concept.
No synchronized keyword, only place you had to take a little care was if you
used shared memory (which was rare)
The other evening I decided to try to implement my version of what is also
known as the Actor pattern. Inspired by Donovan Preston's (@donovanpreston)
talk at Pycon 2010 about his implementation of Actor's in Python I decided
to roll my own.
It is a simple as it gets. Subclasses of Task run in their own thread.
Task's can access each other by calling get_service( "OtherTask" ) to get
a Proxy for that Task. You can call all methods on the other Task. The Method
is sent on a Queue and executed in the other Task's thread.
If you need a return value you can use the Future patten.
Every task can listen on other Task's via the add_listener( "OtherTask" )
method. A listener must implement all Output methods of the Task being
Every Task has a State (default is it self), which handle all incoming
Methods. This means that States in Task are very easy to implement.
No thought or time whatsoever has been put into performance, this is a study
run test test program by simply doing:
$ python pywork.py
Works on python, jython and IronPython (around version >= 2.6)
Copyright (C) 2012-