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):
       """run() is where all the work is done; this is called by TaskMgr()"""
       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


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

Uploaded Source

Built Distribution

polymer-0.0.9-py2.py3-none-any.whl (9.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for polymer-0.0.9.tar.gz
Algorithm Hash digest
SHA256 6962a18c18251ddc50fa64288c84a0f8fcee7c08acb46f62fe2167b0e689c7aa
MD5 01f21d374c44f05895d5746d5bfe706e
BLAKE2b-256 4977cb26d713fe79c49b8c17d2e34c9eb8bfe44c0b822787186a664029dc5b08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for polymer-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4bb132559be07f6c4adac67a98e26aefcac0eee6383fe0d28cd6f70e4f41effb
MD5 44a154912824740cb4fe5c31a0b99b29
BLAKE2b-256 c7a260315588015a9615169f98121528e725071e36565fbf3c1ea604b103b7df

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