mirror of https://github.com/peter4431/rq.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
866 B
Python
35 lines
866 B
Python
import os
|
|
import time
|
|
from rq import Queue, use_connection
|
|
from fib import slow_fib
|
|
|
|
# Tell RQ what Redis connection to use
|
|
use_connection()
|
|
# Range of Fibonacci numbers to compute
|
|
fib_range = range(20, 34)
|
|
|
|
# Kick off the tasks asynchronously
|
|
async_results = {}
|
|
q = Queue()
|
|
for x in fib_range:
|
|
async_results[x] = q.enqueue(slow_fib, x)
|
|
|
|
start_time = time.time()
|
|
done = False
|
|
while not done:
|
|
os.system('clear')
|
|
print 'Asynchronously: (now = %.2f)' % (time.time() - start_time)
|
|
done = True
|
|
for x in fib_range:
|
|
result = async_results[x].return_value
|
|
if result is None:
|
|
done = False
|
|
result = '(calculating)'
|
|
print 'fib(%d) = %s' % (x, result)
|
|
print ''
|
|
print 'To start the actual in the background, run a worker:'
|
|
print ' python examples/run_worker.py'
|
|
time.sleep(0.2)
|
|
|
|
print 'Done'
|