Polymer
Project description
Summary
A simple framework to run tasks in parallel.
Usage
from multiprocessing import Process, Queue
from Queue import Empty, Full
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):
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"""
def __init__(self):
c_q = ControllerQueue()
tasks = list()
## Build ten tasks... do *not* depend on execution order...
num_tasks = 10
for ii in range(1, num_tasks):
tasks.append(SimpleTask(text="Task {0}".format(ii), wait=ii))
args = {
'queue': c_q,
'work_todo': tasks,
'log_level': 0,
'worker_count': 3,
'worker_cycle_sleep': 0.001,
}
## 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.4.tar.gz
(18.6 kB
view details)
Built Distribution
File details
Details for the file polymer-0.0.4.tar.gz
.
File metadata
- Download URL: polymer-0.0.4.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef5c13de9510cad2679a8f14e86d8840cd640e2ae48e91c7a6d50c14d9045c28 |
|
MD5 | 4a3fd237ff253893e9cbd90f06fa087f |
|
BLAKE2b-256 | 0409059f47ba5f3ef1db7b84de9f89fc68a03151c72d4f0b4c3cebbf6d3e63d0 |
File details
Details for the file polymer-0.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: polymer-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2228eb3795f41e9c50ecf045a9b4601a1d0cd85eb7769dcf7c37af3eb4a5f3cf |
|
MD5 | 9d5e8c290b8a4a41db9e14492f83669b |
|
BLAKE2b-256 | bfcbe81e8624d7709a3dbcf68d6be1b9c668bf712970b6d6b3b8c0dba0b349e9 |