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()"""
       ## 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


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

Uploaded Source

Built Distribution

polymer-0.0.18-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: polymer-0.0.18.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for polymer-0.0.18.tar.gz
Algorithm Hash digest
SHA256 70ff2332b78a09a6e04d5eedf372c0c3578f6fce82a56cc99e91e97b7f78a1fa
MD5 5db848feba587faa3eba42f3becb353c
BLAKE2b-256 42e432311904c34764f4ddbba207064f5161c0a9682d5307496f77273d610cb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polymer-0.0.18-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for polymer-0.0.18-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 95f71aa6e4a21035466f19a714c48a34588ed29f464dad9b5ad68a4097946f2c
MD5 e9346f57617fe052c1d18d51b343d8f0
BLAKE2b-256 dd9e5c564fe65ec9a5eb7cef305b022343c09370ed7b4755bab58d36427702ca

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