本文整理汇总了Python中pulsar.utils.pep.range函数的典型用法代码示例。如果您正苦于以下问题:Python range函数的具体用法?Python range怎么用?Python range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_stream
def request_stream(self, request):
m = request.urlargs['m']
n = request.urlargs['n']
if m*n > 8388608:
# limit at 8 megabytes of total data
raise HttpException(status=403)
stream = ('Chunk %s\n%s\n\n' % (i+1, ''.join((
choice(characters) for _ in range(m)))) for i in range(n))
request.response.content = stream
return request.response
示例2: randompaths
def randompaths(request, num_paths=1, size=250, mu=0, sigma=1):
'''Lists of random walks.'''
r = []
for p in range(num_paths):
v = 0
path = [v]
r.append(path)
for t in range(size):
v += normalvariate(mu, sigma)
path.append(v)
return r
示例3: spawn_actors
def spawn_actors(self):
'''Spawn new actors if needed. If the :class:`PoolMixin` is spawning
do nothing.'''
to_spawn = self.cfg.workers - len(self.managed_actors)
if self.cfg.workers and to_spawn > 0:
for _ in range(to_spawn):
self.spawn()
示例4: spawn_actors
def spawn_actors(self, monitor):
'''Spawn new actors if needed.
'''
to_spawn = monitor.cfg.workers - len(self.managed_actors)
if monitor.cfg.workers and to_spawn > 0:
for _ in range(to_spawn):
monitor.spawn()
示例5: testTimeIt
def testTimeIt(self):
msg = b''.join((b'a' for x in range(2**10)))
response = self.pool.timeit(10, self.server.address, msg)
yield response
self.assertTrue(response.locked_time >= 0)
self.assertTrue(response.total_time >= response.locked_time)
self.assertEqual(response.num_failures, 0)
示例6: timeit
def timeit(self, func, times, *args, **kwargs):
'''Usefull little utility for timing responses from server. The
usage is simple::
>>> from pulsar.apps import rpc
>>> p = rpc.JsonProxy('http://127.0.0.1:8060')
>>> p.timeit('ping',10)
0.56...
'''
func = getattr(self, func)
return multi_async((func(*args, **kwargs) for t in range(times)))
示例7: stop_actors
def stop_actors(self):
"""Maintain the number of workers by spawning or killing as required
"""
if self.cfg.workers:
num_to_kill = len(self.managed_actors) - self.cfg.workers
for i in range(num_to_kill, 0, -1):
w, kage = 0, sys.maxsize
for worker in itervalues(self.managed_actors):
age = worker.impl.age
if age < kage:
w, kage = w, age
self.manage_actor(w, True)
示例8: testStreamed
def testStreamed(self):
stream = ('line {0}\n'.format(l+1) for l in range(10))
r = wsgi.WsgiResponse(content=stream)
self.assertEqual(r.status_code, 200)
self.assertEqual(r.status, '200 OK')
self.assertEqual(r.content, stream)
self.assertTrue(r.is_streamed)
data = []
for l, a in enumerate(r):
data.append(a)
self.assertTrue(r.started)
self.assertEqual(a, ('line {0}\n'.format(l+1)).encode('utf-8'))
self.assertEqual(len(data), 10)
示例9: _call
def _call(self):
simple = lambda info, *args: info
testMethod = self.testMethod
testStartUp = getattr(self.test, 'startUp', lambda: None)
testGetTime = getattr(self.test, 'getTime', lambda dt: dt)
testGetInfo = getattr(self.test, 'getInfo', simple)
testGetSummary = getattr(self.test, 'getSummary', simple)
t = 0
t2 = 0
info = {}
for r in range(self.number):
testStartUp()
start = default_timer()
yield testMethod()
delta = default_timer() - start
dt = testGetTime(delta)
testGetInfo(info, delta, dt)
t += dt
t2 += dt*dt
self.updateSummary(info, self.number, t, t2)
self.set_test_attribute('bench_info',
testGetSummary(info, self.number, t, t2))
示例10: _run_once
def _run_once(self, timeout=None):
timeout = timeout or self.poll_timeout
self._num_loops += 1
#
# Compute the desired timeout
if self._callbacks:
timeout = 0
elif self._scheduled:
timeout = min(max(0, self._scheduled[0].deadline - self.timer()),
timeout)
# poll events
self._poll(timeout)
#
# append scheduled callback
now = self.timer()
while self._scheduled and self._scheduled[0].deadline <= now:
self._callbacks.append(heappop(self._scheduled))
#
# Run callbacks
callbacks = self._callbacks
todo = len(callbacks)
for i in range(todo):
exc_info = None
callback = callbacks.popleft()
try:
value = callback()
except socket.error as e:
if raise_socket_error(e) and self.running:
exc_info = sys.exc_info()
if self._raise_loop_error(e):
exc_info = sys.exc_info()
except Exception:
exc_info = sys.exc_info()
else:
if isgenerator(value):
self.task_factory(value, event_loop=self)
if exc_info:
Failure(exc_info).log(
msg='Unhadled exception in event loop callback.')
示例11: timeit
def timeit(self, times, *args, **kwargs):
'''Send ``times`` requests asynchronously and evaluate the time
taken to obtain all responses. In the standard implementation
this method will open ``times`` :class:`Connection` with the
remote server.
Usage::
client = Client(...)
multi = client.timeit(100, ...)
response = yield multi
multi.total_time
:return: a :class:`MultiDeferred` which results in the list of results
for the individual requests. Its :attr:`MultiDeferred.total_time`
attribute indicates the number of seconds taken (once the deferred
has been called back).
'''
results = []
for _ in range(times):
r = self.request(*args, **kwargs)
if hasattr(r, 'on_finished'):
r = r.on_finished
results.append(r)
return multi_async(results)
示例12: random_string
def random_string(characters=None, len=20):
characters or default_characters
return ''.join((choice(characters) for s in range(len)))
示例13: on_message
def on_message(self, websocket, msg):
websocket.write(json.dumps([(i, random()) for i in range(100)]))
示例14: getsize
def getsize(self, request):
size = request.urlargs["size"]
data = {"size": size, "data": "".join(("d" for n in range(size)))}
return self.info_data_response(request, **data)
示例15: __call__
def __call__(self, func, *args, **kwargs):
self.start = self._loop.time()
data = (func(*args, **kwargs) for t in range(self.times))
self.result = multi_async(data, loop=self._loop)
return chain_future(self.result, callback=self._done)