本文整理汇总了Python中hotqueue.HotQueue.put方法的典型用法代码示例。如果您正苦于以下问题:Python HotQueue.put方法的具体用法?Python HotQueue.put怎么用?Python HotQueue.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hotqueue.HotQueue
的用法示例。
在下文中一共展示了HotQueue.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def make(name, path, sentinals):
q = HotQueue(name)
with open(path) as f:
for line in f.readlines():
q.put(line.strip().split('\t'))
for n in xrange(sentinals):
q.put(None)
示例2: unsubscribe_uuid
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def unsubscribe_uuid(cls, uuid):
if True: #TODO: check uuid
queue = HotQueue("connection_thread_id_queue=" + str(g.connection_thread_id))
msg = {'cmd': 'unsubscribe', 'params': str(uuid)}
queue.put(json.dumps(msg))
return msg
else:
return None
示例3: open
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def open(self):
print "Opening"
logging.info("opening")
print "Initializing queue"
queue = HotQueue("myqueue", host="localhost", port=6379, db=0)
count = 0
while count < 100:
count = count + 1
print "adding " + str(count) + " to queue"
queue.put(count)
示例4: RedisMQ
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
class RedisMQ(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
else:
self.app = None
self._tasks = {}
def init_app(self, app):
name = app.config.setdefault('REDISMQ_NAME', 'mq')
host = app.config.setdefault('REDISMQ_HOST', 'localhost')
port = app.config.setdefault('REDISMQ_PORT', 6379)
db = app.config.setdefault('REDISMQ_DB', 0)
password = app.config.setdefault('REDISMQ_PASSWORD', None)
app.config.get('REDISMQ_BLOCK', True),
app.config.get('REDISMQ_BLOCK_TIMEOUT', 0)
if not hasattr(app, 'extensions'):
app.extensions = {}
app.extensions['redismq'] = self
self.app = app
self._hq = HotQueue(name, host=host, port=port, db=db,
password=password)
def task(self, func):
func_name = "%s.%s" % (func.__module__, func.__name__)
self._tasks[func_name] = func
@wraps(func)
def _func(*args, **kwargs):
self._hq.put((func_name, args, kwargs))
setattr(func, "async", _func)
return func
def work(self, *args, **kwargs):
kwargs.update({
'block': self.app.config.get('REDISMQ_BLOCK', True),
'timeout': self.app.config.get('REDISMQ_BLOCK_TIMEOUT', 0)
})
@self._hq.worker(*args, **kwargs)
def _worker(msg):
try:
func_name, args, kwargs = msg
self._tasks[func_name](*args, **kwargs)
except Exception, e:
pass
return _worker()
示例5: output_category
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def output_category(cat,data):
global redis_enabled, appcfg
pp.pprint(data)
print "{cat} Entries: {size}".format(cat=cat,size=len(data))
if appcfg['redis']:
queue = HotQueue(
appcfg['queue_name'], host=appcfg['redis_host'], port=appcfg['redis_port'], db=appcfg['redis_db']
)
for item in data:
queue.put(item)
示例6: test_from_key
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def test_from_key(self):
"""Test the HotQueue.from_key static method"""
redis = Redis()
queues = {
'_test:tens': range(10, 20),
'_test:twenties': range(20, 30),
'_test:thirties': range(30, 40)
}
for name, values in queues.items():
q = HotQueue(name)
q.put(*values)
for key in redis.keys('hotqueue:_test:*'):
q = HotQueue.from_key(key)
self.assertEqual(
list(q.consume(block=False)),
queues[q.name]
)
示例7: main
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def main():
parser = OptionParser(usage="usage: %prog [options]",
version="%prog 1.0")
parser.add_option("-f", "--filename",
dest="filename",
help="Use prerecorded audio file")
parser.add_option("-s", "--string",
dest="string",
help="Use custom string",)
(options, args) = parser.parse_args()
text = None
if options.string:
text = options.string
elif options.filename:
text = googlevoice.recognize(options.filename)
else:
# Record audio:
var = raw_input("Druk <Enter> om de opname te starten: ")
filename = "tmp/recordings/%s.wav" % base64.b64encode(os.urandom(6)).replace("/", "")
soundrecorder.record(filename)
text = googlevoice.recognize(filename)
if text:
text = text.lower()
time = parsetime.parse(text)
artist_uri = parseartist.parse(text)
# TODO: read Spotify user from properties
default_uri = "spotify:user:bertspaan:starred"
if not artist_uri:
artist_uri = default_uri
print "Alarm:", time, "with", artist_uri
if time:
queue_time = HotQueue("wekkie:time")
queue_time.put(time)
if artist_uri:
queue_spotify_uri = HotQueue("wekkie:uri")
queue_spotify_uri.put(artist_uri)
示例8: main
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
def main(argv) :
global q
featureName = argv[1]
featureStatus = argv[2]
featureServer = argv[3]
q = HotQueue(('server_'+featureName), host="localhost", port=6379, db=0)
r_server = redis.Redis('localhost')
if featureStatus == "ON":
q.put('http://127.0.0.1:'+featureServer)
if(not r_server.exists(featureName)):
r_server.set(featureName, '1')
else:
r_server.incr(featureName)
print 'set key value is: ' + r_server.get(featureName)
else :
k = list()
while(1) :
x = q.get()
print "Queue get : ", x
if x is None :
break;
else :
if x == ('http://127.0.0.1:'+featureServer) :
print("Removing : ",x)
if(r_server.get(featureName) > 0):
r_server.decr(featureName)
print 'set key value is: ' + r_server.get(featureName)
break
else:
k.append(x)
while len(k) != 0:
x = k.pop(0)
q.put(x)
printQueue()
print "Queue name : ",('server_'+featureName)
示例9: execfile
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
execfile(activate_this, dict(__file__=activate_this))
from web.config import config, r
from hotqueue import HotQueue
from web.job import read_job, JobObj
from time import time, sleep
# start a thread for listing qlog
qlog = HotQueue(
'joblog',
host=config.get('redis', 'host'),
port=config.getint('redis', 'port'),
password=config.get('redis', 'password'),
db=0)
qlog.put({'cmd': 'purge'})
def loop_handle(log):
if 'cmd' not in log:
return
cmd = log['cmd']
if 'host' in log:
r.set('host:{}:last_alive'.format(log['host']), time())
if cmd in ('available', 'busy'):
r.set('host:{}:status'.format(log['host']), cmd)
return
if cmd == 'purge':
# search all projects done last 48h
示例10: HotQueueTestCase
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
class HotQueueTestCase(unittest.TestCase):
def setUp(self):
"""Create the queue instance before the test."""
self.queue = HotQueue('testqueue')
def tearDown(self):
"""Clear the queue after the test."""
self.queue.clear()
def test_arguments(self):
"""Test that HotQueue.__init__ accepts arguments correctly, and that
the Redis key is correctly formed.
"""
kwargs = {
'name': "testqueue",
'serializer': DummySerializer,
'host': "localhost",
'port': 6379,
'db': 0}
# Instantiate the HotQueue instance:
self.queue = HotQueue(**kwargs)
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertEqual(self.queue.serializer, kwargs['serializer'])
# Instantiate a HotQueue instance with only the required args:
self.queue = HotQueue(kwargs['name'])
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertTrue(self.queue.serializer is pickle) # Defaults to cPickle
# or pickle, depending
# on the platform.
def test_consume(self):
"""Test the consume generator method."""
nums = [1, 2, 3, 4, 5, 6, 7, 8]
# Test blocking with timeout:
nums_added = self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(timeout=1):
msgs.append(msg)
self.assertEqual(msgs, nums_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
# Test non-blocking:
nums_added = self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(block=False):
msgs.append(msg)
self.assertEqual(msgs, nums_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
def test_nack(self):
"""Test the consume generator method."""
nums_added = self.queue.put("1")
msg = self.queue.get() #1
self.assertEqual(msg, nums_added[0])
self.queue.nack(msg.get_reservationId())
msg = self.queue.get() #2
self.assertEqual(msg, nums_added[0])
self.queue.nack(msg.get_reservationId())
msg = self.queue.get() #3
if msg:
self.assertEqual(msg, nums_added[0])
self.queue.ack(msg.get_reservationId())
self.assertEqual(msg, nums_added[0])
self.assertEqual(len(self.queue), 0)
self.assertEqual(msg.get_deliveryCount(),3) #3
def test_cleared(self):
"""Test for correct behaviour if the Redis list does not exist."""
self.assertEqual(len(self.queue), 0)
self.assertEqual(self.queue.get(), None)
def test_get_order(self):
"""Test that messages are get in the same order they are put."""
alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
msg_added = []
msg_added.extend(self.queue.put(alphabet[0], alphabet[1], alphabet[2]))
msg_added.extend(self.queue.put(alphabet[3]))
msg_added.extend(self.queue.put(alphabet[4]))
msgs = []
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
self.assertEqual(msgs, msg_added)
for msg in msgs:
self.queue.ack(msg.get_reservationId())
def test_length(self):
"""Test that the length of a queue is returned correctly."""
self.queue.put('a message')
self.queue.put('another message')
self.assertEqual(len(self.queue), 2)
#.........这里部分代码省略.........
示例11: HotQueue
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
sys.path = [os.path.join(os.path.dirname(__file__))] + sys.path
from web.config import config, r
from hotqueue import HotQueue
from web.job import read_job, JobObj
from time import time, sleep
# start a thread for listing qlog
qlog = HotQueue(
'joblog',
host=config.get('redis', 'host'),
port=config.getint('redis', 'port'),
password=config.get('redis', 'password'),
db=0)
qlog.put({'cmd': 'purge', 'uid': 'moij'})
def loop_handle(log):
print log
if 'cmd' not in log or 'uid' not in log:
return
cmd = log['cmd']
uid = log['uid']
if cmd == 'purge':
# search all projects done last 48h
keys = r.keys('job:*:dt_added')
print keys
to_delete = []
ctime = time()
for key in keys:
示例12: HotQueue
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
queue = HotQueue("serial_message_queue", host="localhost", port=6379, db=0)
# q.put('hello world')
i = 0
# messages = []
message = [datetime.now()]
number = ""
new_message = False
while True:
y = ser.read()
if y == "\r":
new_message = True
queue.put(message)
print(message)
# messages.append(message)
message = [datetime.now()]
elif y == " ":
if number != "":
message.append(float(number))
number = ""
else:
number = number + y
i += 1
# print(messages)
ser.close()
开发者ID:sebnil,项目名称:Realtime-Serial-Port-plotter-in-Python-using-Bokeh,代码行数:32,代码来源:read_serial_redis.py
示例13: HotQueue
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
from apscheduler.jobstores.sqlalchemy_store import SQLAlchemyJobStore
from dateutil.tz import gettz
from datetime import datetime, timedelta
from apscheduler.triggers import IntervalTrigger, DateTrigger
from apscheduler.scripts import HttpScript, CommandScript
if __name__ == '__main__':
queue = HotQueue('job_changes')
script = HttpScript(url='http://baidu.comm')
store = SQLAlchemyJobStore(url='sqlite:////tmp/task.db', tablename='tasks')
#script = CommandScript(command='ping -c 3 www.baidu.com')
local_tz = gettz('Asia/Chongqing')
defaults = {'timezone': local_tz}
trigger = IntervalTrigger(defaults, seconds=60)
#trigger = DateTrigger(defaults, run_date=datetime(2013,12,11, 8, 11))
job = Job(name=u'BaiduCurlWithWrongUrl', script=script, trigger=trigger)
#print job.run()
now = datetime.now(local_tz)
next_run_time = job.compute_next_run_time(now)
print job.get_run_times(now+timedelta(seconds=60))
if next_run_time:
print "add job"
print job
store.add_job(job)
queue.put({'opt_type':'add', 'job_id':job.id})
示例14: HotQueueTestCase
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
class HotQueueTestCase(unittest.TestCase):
def setUp(self):
"""Create the queue instance before the test."""
self.queue = HotQueue('testqueue')
def tearDown(self):
"""Clear the queue after the test."""
self.queue.clear()
def test_arguments(self):
"""Test that HotQueue.__init__ accepts arguments correctly, and that
the Redis key is correctly formed.
"""
kwargs = {
'name': "testqueue",
'serializer': DummySerializer,
'host': "localhost",
'port': 6379,
'db': 0}
# Instantiate the HotQueue instance:
self.queue = HotQueue(**kwargs)
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertEqual(self.queue.serializer, kwargs['serializer'])
self.assertEqual(self.queue._HotQueue__redis.host, kwargs['host'])
self.assertEqual(self.queue._HotQueue__redis.host, kwargs['host'])
self.assertEqual(self.queue._HotQueue__redis.port, kwargs['port'])
self.assertEqual(self.queue._HotQueue__redis.db, kwargs['db'])
# Instantiate a HotQueue instance with only the required args:
self.queue = HotQueue(kwargs['name'])
# Ensure that the properties of the instance are as expected:
self.assertEqual(self.queue.name, kwargs['name'])
self.assertEqual(self.queue.key, "hotqueue:%s" % kwargs['name'])
self.assertTrue(self.queue.serializer is pickle) # Defaults to cPickle or
# pickle, depending on the
# platform.
def test_consume(self):
"""Test the consume generator method."""
nums = [1, 2, 3, 4, 5, 6, 7, 8]
# Test blocking with timeout:
self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(timeout=1):
msgs.append(msg)
self.assertEquals(msgs, nums)
# Test non-blocking:
self.queue.put(*nums)
msgs = []
for msg in self.queue.consume(block=False):
msgs.append(msg)
self.assertEquals(msgs, nums)
def test_cleared(self):
"""Test for correct behaviour if the Redis list does not exist."""
self.assertEquals(len(self.queue), 0)
self.assertEquals(self.queue.get(), None)
def test_get_order(self):
"""Test that messages are get in the same order they are put."""
alphabet = ['abc', 'def', 'ghi', 'jkl', 'mno']
self.queue.put(alphabet[0], alphabet[1], alphabet[2])
self.queue.put(alphabet[3])
self.queue.put(alphabet[4])
msgs = []
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
msgs.append(self.queue.get())
self.assertEquals(msgs, alphabet)
def test_length(self):
"""Test that the length of a queue is returned correctly."""
self.queue.put('a message')
self.queue.put('another message')
self.assertEquals(len(self.queue), 2)
def test_worker(self):
"""Test the worker decorator."""
colors = ['blue', 'green', 'red', 'pink', 'black']
# Test blocking with timeout:
self.queue.put(*colors)
msgs = []
@self.queue.worker(timeout=1)
def appender(msg):
msgs.append(msg)
appender()
self.assertEqual(msgs, colors)
# Test non-blocking:
self.queue.put(*colors)
msgs = []
@self.queue.worker(block=False)
def appender(msg):
msgs.append(msg)
appender()
self.assertEqual(msgs, colors)
#.........这里部分代码省略.........
示例15: HotQueue
# 需要导入模块: from hotqueue import HotQueue [as 别名]
# 或者: from hotqueue.HotQueue import put [as 别名]
import ConfigParser
import psycopg2
from hotqueue import HotQueue
config = ConfigParser.ConfigParser()
config.read(['api.conf', 'local_api.conf'])
dbhost = config.get('Database', 'dbhost')
dbname = config.get('Database', 'dbname')
dbuser = config.get('Database', 'dbuser')
dbpass = config.get('Database', 'dbpass')
dbport = config.get('Database', 'dbport')
redisdb = config.get('Redis', 'redishost')
queue = HotQueue("killboard-API", host=redisdb, port=6379, db=0)
if not dbpass:
# Connect without password
dbcon = psycopg2.connect("host="+dbhost+" user="+dbuser+" dbname="+dbname+" port="+dbport)
else:
dbcon = psycopg2.connect("host="+dbhost+" user="+dbuser+" password="+dbpass+" dbname="+dbname+" port="+dbport)
curs = dbcon.cursor()
curs2 = dbcon.cursor()
curs.execute("""select id from killapi where updtime <= now()""")
for api in curs:
sqlid = api[0]
curs2.execute("""update killapi set updtime = (now() + interval '15 minutes') where id = %s""", (sqlid,))
queue.put(sqlid)