Multi-Thread programming should be easy and automated to the core, leaving free developers' focus on application problem, ensuring maximum comfort with confidence to parallelism and asynchronous event handling. Other goals followed by Workersz project are minimizing the bureaucracy and providing compatibility with existing code (currently tested with python 2.7).
In resume Workersz is python framework to deal with thread pools. Every thread pool contains a task-scheduler event loop that exhaust task in queue to free workers. It distributes any python function as target data in Task class object. Target could be synchronized or none, depending on developer choice of architecture or style. Workers in pool will lock or not on shared resources within target. On done task event handler are implemented in asynchronous application with error event handlers. All callbacks ( event handlers) on their side could be targeted to same or another pool or in __main__ process.
Currently status of project is working beta. Python package and docs will be released soon. Any participation is welcome! Work is licensed under terms of Apache 2.0.
WorkerPool may used conveniently with automation provided from own decorator. Here is the example of non-blocking socket server using it:
https://github.com/workersz/workersz/blob/master/examples/srvd_deco.py
вторник, 25 август 2015 г.
понеделник, 10 август 2015 г.
Python function make-up for the make-up artists.
Some ideas how and for what to use function decorator part one:
the problem:
def one( *args, **kwargs ):
if kwargs['goodone'] == 1:
return 1
else:
return 0
a lot of code rely on exception handling and you must surround it with try catch...
one(123)
will raise KeyError
Do you know the tale: " Ask the lazy man to do work in and he will teach you! " или на български: Накарай мързеливия да работи за да те научи на акъл!
And here decoration or wrap will save us a lot of try-except-try-excpet spaghetti code:
# our reusable error handling function:
def error_handle( args,kwargs,e ):
print "handling error: ",repr(e)
# the make-up artist: try except python decorator
def try_wrap( func, exception_class, exception_handle ):
def wrap(*args, **kwargs):
try:
return func( *args, **kwargs )
except exception_class, e:
return exception_handle(args, kwargs, e )
return wrap
# apply the make up:
one = try_wrap(one, KeyError, error_handle)
one(123)
Абонамент за:
Публикации (Atom)