Skip to content

Instantly share code, notes, and snippets.

@chao-he
Last active December 29, 2015 09:59
Show Gist options
  • Save chao-he/7654281 to your computer and use it in GitHub Desktop.
Save chao-he/7654281 to your computer and use it in GitHub Desktop.
beanstalk client
#!/usr/bin/env python26
import sys
from tornado import ioloop
from tornado.options import define,options,parse_command_line
from beanstalkt import Client as BeansClient
define("bs_host", default="localhost")
define("bs_port", default=11300)
define("using", default="input")
def main(client):
def push(data):
data = sys.stdin.readline()
if data:
client.put(data.strip(), ttr=600, callback=push)
else:
ioloop.IOLoop.instance().stop()
client.connect(lambda: client.use(options.using, push))
ioloop.IOLoop.instance().start()
if __name__ == "__main__":
parse_command_line()
client = BeansClient(options.bs_host, options.bs_port)
main(client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment