semvec/pypi-packages huggingface dataset:
taskutils 0.2
A multithreaded task scheduler for task queues and recurrent tasks
License: BSD
Keywords: task scheduler

# tasktuils

**taskutils** is a implements a multithreaded scheduler in Python. 
It provide methods to enqueue tasks and set simple policies, for example:

- execute once with this priority
- execute every 10 minutes
- retry twice if it fails
- execute no more than 3 tasks concurrently

It can used to power more complex programs that need concurrency, for example a crawler.

Here is an example of usage:

### Install it

    pip install taskutils

### Import the relevant objects

    from taskutils import TaskHandler, Task, Recurrent

### Create the main task handler object

    task_handler = TaskHandler(max_num_threads=3, sleep_seconds=2)

This will create 3 threads that wait for tasks to be queued every 2 seconds.

### Queue some simple tasks

    def foo(k): print 'hello world from task %s' % k

    for k in range(10):
        task = Task(foo, kwargs=dict(k=k), priority=k, repeats_on_failure=3)
        task_handler.enqueue_task(task)

This will enqueue 10 tasks (with arbitrary parameter k=0...9) which will be executed by
the task handler threads when free. If a task fails it will be retried 3 times before being 
discarded. Notice that a task contain a function (in this case foo) and its arguments.

### Queue a recurrent task

    task = Task(foo, kwargs=dict(k=10), repeats_on_failure=0)
    task_handler.recurrent_tasks['abc'] = Recurrent(task, interval=3, repeats=5)

Recurrent tasks are wrapped into the Recurrent() object and must be named (for example 'abc').
Recurrent tasks are named because they are not placed in the normal queue but are executed always 
with max priority when their time comes. In the above example the 'abc' task is executed 
5 times every 3 seconds. A recurrent task can be removed via

    del task_handler.recurrent_tasks['abc']

### Other goodies

    from taskutils import LockWrapper
    with_a_lock = LockWrapper()

It defines a decorator that makes sure all code called with the decorator is always serialized, even if called in different Tasks:

    @with_a_lock
    def f(): print 'a'
    
    @with_a_lock
    def g(): print 'b'

    task_handler.enqueue_task(Task(f))
    task_handler.enqueue_task(Task(g))

This makes sure that the excution of functions f and g is never concurrent.

## License

Created by Massimo Di Pierro (http://experts4solutions.com) @2016 BSDv3 License
buckingham 0.2
A library for unit conversion and error propagation
License: BSD
Keywords: unit conversion and error propagation

Example of dimensional analysis and conversions
===============================================

Install with

    pip install buckingham

Example:

    >>> a = Number(10,dims='meter/second')
    >>> b = Number(2,dims='yard/minute')
    >>> c = a + b
    >>> print c.convert('kilometer/hour')
    (36.109728 ± 0)

    >>> print c.value, c.error
    10.03048 0.0

Without conversion results are alwayws in:
  meters, seconds, grams, ampere, kelvin, dollar (and combination)

The error is the standard deviation assuming the true value
is Normal distributed

Error propagation assumes independence

    >>> a = Number(1,dims='decimeter^3')
    >>> b = Number(2,dims='liter')
    >>> c = Number(5,dims='gram/centimeter^3')
    >>> d = (a + b)*c
    >>> print d.convert('kilogram')
    (15.000000 ± 0)

Example of formula validation

    >>> a = Number(10,dims='meter/second')
    >>> b = Number(2,dims='yard^3')
    >>> c = a + b
    Traceback (most recent call last):
    ...
    RuntimeError: Incompatible Dimentions

Examples of error propagation:

    >>> a = Number(10,error=2,dims='meter/second') # (10±2)m/s
    >>> b = Number(5,error=1,dims='hour')  # (5±1)h
    >>> c = a*b
    >>> print c.convert('kilometer')
    (1.800 ± 0.509)x10^2
    >>> print c.convert('kilometer').value
    180.0
    >>> print c.convert('kilometer').error
    50.9116882454

Examples of more complex formulas

    >>> print a**4/(7*b)
    (7.94 ± 6.54)/10^2

(last result is implicitely in meter**4/second**5)

Financial application example:

    >>> coupon = Number(200,error=1,dims="dollar/day")
    >>> expiration = Number(1,error=0,dims="year")
    >>> payoff = coupon*expiration
    >>> print payoff.convert('dollar')
    (7.3048 ± 0.0365)x10^4

I.e. $73048 dollars with $365 dollas of one sigma uncertainly
    
## License

Created by Massimo Di Pierro (http://experts4solutions.com) @2016 BSDv3 License