skip to navigation
skip to content

Not Logged In

swarm 0.0.2-dev

multiprocessing based framework for tasks humanization

DESCRIPTION

Parallel processing for humans

OUTLINE

multiprocessing based framework that uses codeblocks.py atomization layer.

Main area of swarm application is web crawlers, mass parsers or email senders with complex internal behaviour.

EXAMPLE

import logging
import sys
import time
import random
from swarm import BaseSwarm as Swarm, define_swarm, atomic, swarm

class config:
    # number of pool workers. Defaults to `multiprocessing.cpu_count()`
    COMPETITORS = 10
    # just set log level and and enjoy
    # `swarm.log.[debug|info|error]('Message')` inside pool workers
    LOG_LEVEL = logging.INFO

calculator = Swarm(__name__)
calculator.config.from_object(config)

define_swarm.start()
@calculator.sync
def squares_of_range(x):
    #current_process() == <MainProcess>
    for i in range(1, x):
        #code inside `atomic()` context pushed into pool asyncronously
        with atomic() << _:
            # current_process() == <PoolWorker-X>

            # transparently takes `i` variable from outer world
            # and sends all generated items to items queue of top @sync function
            yield i*i

            # internally required modules are also imported into PoolWorker
            time.sleep(round(random.random(),3))

            #message that exceeds log level does not leave process bounds
            swarm.log.debug('Calculated result for %s'%i)

            if i > 3:
                swarm.log.error('Oh no! %s is too much for me!'%i)
    #this function will only finish after all `atomic()`s finished
define_swarm.finish()

if __name__ == '__main__':
    for x in squares_of_range(int(sys.argv[1])):
        print '>', x

FEATURES

  • nested atomic()-s
  • recursion of atomic() calling functions
  • transparent serialization of closures
  • pause/restore
  • explicit namespace management with codeblocks.py namespace management
  • werkzeug like context stacks. Manager and atom level context stacks
  • multiprocessing as parallelization backend
  • wide use of blinker signals for infill customization

WARNING

Currently this is alpha version.

 
  • Downloads (All Versions):
  • 7 downloads in the last day
  • 57 downloads in the last week
  • 216 downloads in the last month
  • Author: Denis Mishchishin
  • Home Page: https://github.com/denz/swarm/0.0.2-dev
  • Download URL: http://github.com/denz/swarm/archive/master.zip#egg=swarm-0.0.2-dev
  • License:
    Copyright (c) 2012, Denis Mishchishin
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in the
          documentation and/or other materials provided with the distribution.
        * Neither the name of the <organization> nor the
          names of its contributors may be used to endorse or promote products
          derived from this software without specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Categories
  • Package Index Owner: denz
  • DOAP record: swarm-0.0.2-dev.xml