Esempio n. 1
0
def main(argv):
    try:
        optlst, args = getopt.getopt(
            argv, 'ht:n:c:', ['help', 'pnum', 'nm', 'nconsumer'])
        nm = 2
        pnum = 2
        nconsumer = 2
        for opt, val in optlst:
            if opt in ('-h', '--help'): # show help message
                show_usage()
            elif opt in ('-t', '--pnum'): # process number
                pnum = int(val)
            elif opt in ('-n', '--nm'): # mismatch num max value
                nm = int(val)
            elif opt in ('-c', '--nconsumer'): # consumer process number
                nconsumer = int(val)
            else:
                show_usage()
    except GetoptError:
        show_usage()

    if not args:                        # no samfile given
        show_usage()

    for arg in args:                    # run each file separate
        run(producer=get_pair, producer_args=(arg,),
            consumer=classify_pair, consumer_kwargs=dict(nm=nm),
            reporter=output_pair, reporter_args=(arg,),
            reporter_kwargs=dict(nm=nm),
            sentinel=SENTINEL, nconsumer=nconsumer, pnum=pnum)
Esempio n. 2
0
def consumer(i):
    # print 'pid:', os.getpid(), 'now process', i
    return i, i ** 3


def _reporter(i, j):
    print 'end:', i, j


def reporter(iqueue, nconsumer=1, sentinel=SENTINEL):
    while True:
        item = iqueue.get()
        if item is sentinel:
            nconsumer -= 1
            if nconsumer < 1:           # done
                break
            continue

        _reporter(*item)


if __name__ == '__main__':
    for num in (10000,):
        run(producer=producer, producer_args=(num,),
            consumer=consumer,
            reporter=reporter,
            nconsumer=10
            )