def listen(func):
import argparse<EOL>import beanstalkc as bean<EOL>parser = argparse.ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', type=int, help="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', type=int, help="<STR_LIT>")<EOL>args = vars(parser.parse_args())<EOL>port = int(args.get('<STR_LIT:port>') or DEFAULT_BEANSTALKD)<EOL>proc = int(args.get('<STR_LIT>') or <NUM_LIT:1>)<EOL>def _listen(func, index):<EOL><INDENT>sys.stdout = open('<STR_LIT>'.format(index), "<STR_LIT:w>", buffering=<NUM_LIT:0>)<EOL>sys.stderr = open('<STR_LIT>'.format(index), "<STR_LIT:w>", buffering=<NUM_LIT:0>)<EOL>bsd = bean.Connection(host=LOCALHOST, port=port)<EOL>while True:<EOL><INDENT>job = bsd.reserve()<EOL>func(json.loads(job.body))<EOL><DEDENT><DEDENT>log.info('<STR_LIT>')<EOL>for i in range(proc):<EOL><INDENT>log.info('<STR_LIT:{}>'.format(i))<EOL>Process(target=_listen, args=(func,i)).start()<EOL><DEDENT>
This function is for use in external scripts in order to listen on the
queue and perform tasks. In particular, create a function which takes the
arguments you would pass to `launch_all`s jobs parameter, then at the
bottom of the script add:

if __name__ == '__main__':
    peri.test.beanstalk.listen(my_function_name)