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)
def Controller():
"""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."""
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))
targs = {
'work_todo': tasks, # a list of SimpleTask() instances
'hot_loop': False, # If True, continuously loop over the tasks
'log_level': 0, # Logging off (debugging=3)
'worker_count': 3, # Number of workers (default: 5)
'resubmit_on_error': False, # Do not retry errored jobs...
'queue': ControllerQueue(),
'worker_cycle_sleep': 0.001, # Worker sleep time after a task
}
## task_mgr reads and executes the queued tasks
task_mgr = TaskMgr(**targs)
## a set() of completed task objects are returned after supervise()
results = task_mgr.supervise()
return results
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.23.tar.gz
(21.2 kB
view details)
Built Distribution
File details
Details for the file polymer-0.0.23.tar.gz
.
File metadata
- Download URL: polymer-0.0.23.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc6e2184ceaede909407954a5d6367f7c8b77e075bc378b7c5d6986f5a9a81f |
|
MD5 | c67f9e810cefcde0fba4964da2406d90 |
|
BLAKE2b-256 | 0fdacb01f551e573d4b981a064fe18a771ce6b678b83f69c6747a091c2d26336 |
File details
Details for the file polymer-0.0.23-py2.py3-none-any.whl
.
File metadata
- Download URL: polymer-0.0.23-py2.py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb174f6a1f854b0f57f55fa6d3fcb8a0f4fca028c20647afc7dc8aa1494336b5 |
|
MD5 | 3c4d53dadc27acd19a91b04c7190ae36 |
|
BLAKE2b-256 | ba19a7f1f71296b9914f95a7ca2797015bce4fabde2274604639f29ab1f0d656 |