BVB Source Codes

rq Show run_example.py Source code

Return Download rq: download run_example.py Source code - Download rq Source code - Type:.py
  1. # -*- coding: utf-8 -*-
  2. from __future__ import (absolute_import, division, print_function,
  3.                         unicode_literals)
  4.  
  5. import os
  6. import time
  7.  
  8. from rq import Connection, Queue
  9.  
  10. from fib import slow_fib
  11.  
  12.  
  13. def main():
  14.     # Range of Fibonacci numbers to compute
  15.     fib_range = range(20, 34)
  16.  
  17.     # Kick off the tasks asynchronously
  18.     async_results = {}
  19.     q = Queue()
  20.     for x in fib_range:
  21.         async_results[x] = q.enqueue(slow_fib, x)
  22.  
  23.     start_time = time.time()
  24.     done = False
  25.     while not done:
  26.         os.system('clear')
  27.         print('Asynchronously: (now = %.2f)' % (time.time() - start_time,))
  28.         done = True
  29.         for x in fib_range:
  30.             result = async_results[x].return_value
  31.             if result is None:
  32.                 done = False
  33.                 result = '(calculating)'
  34.             print('fib(%d) = %s' % (x, result))
  35.         print('')
  36.         print('To start the actual in the background, run a worker:')
  37.         print('    python examples/run_worker.py')
  38.         time.sleep(0.2)
  39.  
  40.     print('Done')
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     # Tell RQ what Redis connection to use
  45.     with Connection():
  46.         main()
  47.  
downloadrun_example.py Source code - Download rq Source code
Related Source Codes/Software:
amazon-dsstne - Deep Scalable Sparse Tensor Network Engine (DSSTNE... 2017-01-08
webpack-demos - a collection of simple demos of Webpack 2017-01-08
Squire - HTML5 rich text editor. Try the demo integration a... 2017-01-08
thor - Thor is a toolkit for building powerful command-li... 2017-01-08
glide - Package Management for Golang h... 2017-01-08
emmet-vim - emmet for vim: http://emmet.io/ ... 2017-01-08
prose - A Content Editor for GitHub. ht... 2017-01-08
sshrc - ring your .bashrc, .vimrc, etc. with you when you ... 2017-01-08
typed.js - A jQuery typing animation script. ... 2017-01-08
find - High-precision indoor positioning framework for mo... 2017-01-08
discover-flask - Full Stack Web Development with Flask. ... 2017-01-12
spring-mvc-showcase - Demonstrates the features of the Spring MVC web fr... 2017-01-12
tushare - TuShare is a utility for crawling historical data ... 2017-01-12
raml-spec - RAML Specification http://raml.... 2017-01-12
android-stackblur - Android StackBlur is a library that can perform a ... 2017-01-12
sound-redux - A Soundcloud client built with React / Redux ... 2017-01-12
httpstat - curl statistics made simple 2017-01-12
vim - Vim configuration file and plug-ins 2017-01-12
appframework - The definitive HTML5 mobile javascript framework ... 2017-01-12
BaiduExporter - Assistant for Baidu to export download links to ar... 2017-01-11

 Back to top