Skip to content

Instantly share code, notes, and snippets.

@davexpro
Created May 1, 2015 15:27
Show Gist options
  • Save davexpro/e96d644a873b0c235418 to your computer and use it in GitHub Desktop.
Save davexpro/e96d644a873b0c235418 to your computer and use it in GitHub Desktop.
#!/user/bom/env python
# coding=utf8
# author=dave
# create=20150501
import time
import gevent
import requests
import gevent.monkey
gevent.monkey.patch_socket()
def fetch(pid, url):
req = requests.get(url)
status = req.status_code
print "[+] Process %s: %s %s" % (pid, url, status)
return pid, url, status
def asynchronous():
i = 0
jobs = []
url = 'http://www.zhihu.com'
for i in range(0, 5000):
jobs.append(gevent.spawn(fetch, i, url))
gevent.joinall(jobs)
if __name__ == "__main__":
start_time = time.time()
asynchronous()
print "[*] Total Time Consumption: " + str(time.time() - start_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment