Polymer
Project description
Summary
A simple framework to run tasks in parallel.
Usage
import time
from polymer.Polymer import ControllerQueue, TaskMgr
from polymer.abc_task import BaseTask
class SimpleTask(BaseTask):
def __init__(self, text="", wait=0.0):
super(SimpleTask, self).__init__()
self.text = text
self.wait = wait
def run(self):
"""run() is where all the work is done; this is called by TaskMgr()"""
## WARNING... using try / except in run() could squash Polymer's
## internal error logging...
time.sleep(float(self.wait/10))
print self.text
def __eq__(self, other):
"""Define how tasks are uniquely identified"""
if other.text==self.text:
return True
return False
def __repr__(self):
return """<{0}, wait: {1}>""".format(self.text, self.wait)
class Controller(object):
"""Controller() builds a list of tasks, and queues them to the TaskMgr
There is nothing special about the name Controller()... it's just some
code to build a list of SimpleTask() instances."""
def __init__(self):
tasks = list()
## Build ten tasks... do *not* depend on execution order...
num_tasks = 10
for ii in range(0, num_tasks):
tasks.append(SimpleTask(text="Task {0}".format(ii), wait=ii))
args = {
'hot_loop': False, # If True, it continuously runs jobs
'queue': ControllerQueue(),
'work_todo': tasks, # List of SimpleTask() instances
'log_level': 0, # Logging off (debugging=3)
'worker_count': 3, # Number of workers (default: 5)
'worker_cycle_sleep': 0.001,
'resubmit_on_error': False, # Do not retry errored jobs...
}
## task_mgr reads and executes the queued tasks
task_mgr = TaskMgr(**args)
## a set() of completed task objects are returned after supervise()
results = task_mgr.supervise()
if __name__=='__main__':
Controller()
License
GPLv3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
polymer-0.0.15.tar.gz
(19.8 kB
view details)
Built Distribution
File details
Details for the file polymer-0.0.15.tar.gz
.
File metadata
- Download URL: polymer-0.0.15.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a12186a1333ae9db55799010e2a3af55b421d661f19debf1480f5940e1e8aaf8 |
|
MD5 | 1f0f15383232eefca93b4925d9efe816 |
|
BLAKE2b-256 | f63fefa99bd83d47940d38c3aebd764b3c646ac06f3edd0a084440f2e35759b9 |
File details
Details for the file polymer-0.0.15-py2.py3-none-any.whl
.
File metadata
- Download URL: polymer-0.0.15-py2.py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58d674b0d0bc7e36c0050079691f22d06d2057a6c77566dc6020b04b83ca4776 |
|
MD5 | 0d769962444c3f4138e373306d2d5772 |
|
BLAKE2b-256 | bd075164aab2b763292a314f25a55b390985ffd4c6a1af56b08a05ccdaaea8a5 |