This file contains 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 |
This file contains 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 <laomo@lmbj.net> | |
# 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 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 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 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 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 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 concurrent.futures import ThreadPoolExecutor | |
from functools import partial, wraps | |
import time | |
import tornado.ioloop | |
import tornado.web | |
EXECUTOR = ThreadPoolExecutor(max_workers=4) |
This file contains 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 concurrent.futures import ThreadPoolExecutor | |
from functools import partial, wraps | |
import time | |
import tornado.ioloop | |
import tornado.web | |
EXECUTOR = ThreadPoolExecutor(max_workers=4) |
This file contains 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
def authenticated(method): | |
"""Decorate methods with this to require that the user be logged in.""" | |
@functools.wraps(method) | |
def wrapper(self, *args, **kwargs): | |
if not self.current_user: | |
if self.request.method == "GET": | |
url = self.get_login_url() | |
if "?" not in url: | |
url += "?" + urllib.urlencode(dict(next=self.request.uri)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer