Comb

comb , A simple and high-performance framework for create parallel program

Documents

Guide

Installation

Automatic installation:

pip install comb

comb is listed in PyPI and can be installed with pip or easy_install. it includes demo applications.

Manual installation: Download the latest source from Github.

git clone  https://github.com/kbonez/comb.git
cd comb
python setup.py build
sudo python setup.py install

The comb source code is hosted on GitHub.

Prerequisites: comb was only test on Python 2.7. It may be runs on all Python versions.

How to use

To use comb, you should create a python module file. we named slot.

A legal slot must be named ‘Slot’ in your module file and it must be at least contain four method:

  • initialize

    initial resource, e.g: database handle

  • __enter__

    get next data to do,you can fetch one or more data.

  • slot

    user custom code

  • __exit__

    when slot finished, call this method

Start

  • Execute a comb is very simple. just execute:

    comb --root SLOT_ROOT_PATH  slot-package.slot-module
    

    if you set SLOTPATH environment, you can use:

    comb slot-package.slot-module
    
  • Quick View. call:

    comb   comb.demo.list
    

this will execute the Deal List Demo

Note

  • You’d better make comb process number equals your cpu core number.
  • We strongly recommend you use comb with supervisor

Code view

comb.slot — Slot base class

Slot
class comb.slot.Slot(combd)[source]

To use comb, you should create a python module file. we named slot.

A legal slot must be named ‘Slot’ in your module file and it must be at least contain four method:

initial resource, e.g: database handle

get next data to do,you can fetch one or more data.

user custom code

when slot finished, call this method

Don’t override this method unless what you’re doing.

Slot.__init__(combd)[source]

Don’t override this method unless what you’re doing.

Slot.__enter__()[source]

You MUST return False when no data to do.

The return value will be used in Slot.slot

Slot.__exit__(exc_type, exc_val, exc_tb)[source]

When slot done, will call this method.

Slot.initialize()[source]

Hook for subclass initialization.

This block is execute before thread initial

Example:

class UserSlot(Slot):
    def initialize(self):
        self.threads_num = 10 

    def slot(self, result):
        ...
Slot.slot(msg)[source]

Add your custom code at here.

For example, look at:

comb.demo.* — Slot demo classes

List.Slot
class comb.demo.list.Slot(combd)[source]

Don’t override this method unless what you’re doing.

Slot.initialize()[source]

Hook for initialization.

This block is execute before thread initial

Example:

class UserSlot(Slot):
    def initialize(self):
        ...

    def slot(self, result):
        ...
Slot.__enter__()[source]
Slot.slot(result)[source]
Slot.__exit__(exc_type, exc_val, exc_tb)[source]
Redis.Slot
class comb.demo.redis.Slot(combd)[source]

Don’t override this method unless what you’re doing.

Slot.initialize()[source]
This block is execute before thread initial

Example:

class UserSlot(Slot):
    def initialize(self,*args,**kwargs):
        self.attr = kwargs.get('attr',None)

    def slot(self, result):
        ...
Slot.__enter__()[source]
Slot.slot(result)[source]
Slot.__exit__(exc_type, exc_val, exc_tb)[source]

Release notes

Planning feature

  • Comb cook book, chinese version
  • move domain kbonez.com to leadyi.com

What’s new in Comb 0.9.x

  • Version 0.9.6
    • Add --no-daemon option.
  • Version 0.9.5
    • User interrupt directly when user specific --debug option.
  • Version 0.9.4
    • change --sleep data type to float in python3.
  • Version 0.9.3
    • update document
    • improve setup.py file
  • Version 0.9.2
    • user interrupt more frequently.
  • Version 0.9.1
    • support python3
  • Version 0.9.0
    • Add --once option. execute once and exit instead of wait.
    • As of Comb 0.8.99, we change --sleep_max option to --sleep-max.
    • change comb script install path,use python library path instead /usr/local/bin