This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import sleep | |
| import tornado | |
| from multiprocessing.pool import ThreadPool | |
| _workers = ThreadPool(10) | |
| class BackgroundMix(tornado.web.RequestHandler): | |
| """将block任务放入线程池中执行 | |
| EXAMPLE: | |
| # blocking task like querying to MySQL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rq import Queue, Worker, Connection | |
| if __name__ == '__main__': | |
| with Connection(): | |
| q = Queue() | |
| Worker(q).work() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tornado import ioloop | |
| from tornado.httpclient import AsyncHttpClient | |
| urls=['http://www.google.com/','http://baidu.com'] | |
| def print_head(response): | |
| print '%s: %s bytes: %r' %(response.request.url,len(response.body),response.body[:50]) | |
| http_client=AsyncHTTPClient() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gevent | |
| from gevent import monkey | |
| #patches stdlib (including socket and ssl modules) to cooperate with other greenlets | |
| monkey.patch_all() | |
| import urllib2 | |
| urls=['http://baidu.com','http://cqu.edu.cn','http://www.python.org'] | |
| def print_head(url): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/bin/bash | |
| # Author : laomo <[email protected]> | |
| # Donate Address : https://ripple.com//send?to=rQKFznLaiyT55YXSS33fE6NgTjKbrnN4gT | |
| sudo apt-get update | |
| sudo apt-get install libxss1 libstdc++5 ia32-libs freeglut3 | |
| #optional(for see the tasks) | |
| sudo apt-get install htop | |
| wget http://boinc.berkeley.edu/dl/boinc_7.2.33_x86_64-pc-linux-gnu.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| import random | |
| import threading | |
| #k thrads | |
| k=4 | |
| #Generate n numbers for each thread to process. | |
| n=10 |
NewerOlder