Skip to main content

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):
       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):

       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': ControllerQueue(),
           '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


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.5.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

polymer-0.0.5-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file polymer-0.0.5.tar.gz.

File metadata

  • Download URL: polymer-0.0.5.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for polymer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 60cc486c1f611cd7b6d12930883573c631c4f5c61ea3ef583dc771ea4040f918
MD5 50fda2d35a31190cbf8c03cdbc89a920
BLAKE2b-256 930a39f6503a9f327ec84fcde0ebd1654197381f12a2a5720cbdfa59fbdf7c12

See more details on using hashes here.

File details

Details for the file polymer-0.0.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for polymer-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 249490d68a06140d7ebac5328fed2cd8667f098449aef7c3421f1e0e1cc6d57d
MD5 dc0acc85b07280f3ee8496577293b177
BLAKE2b-256 dfb28fed2b1ad057efb51edfa5a0cce1a2bd12b2bfedd699663935f90ff136b5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page