Last active
August 29, 2015 14:27
-
-
Save squeaky-pl/c657e1dd2f68a5d0a0e3 to your computer and use it in GitHub Desktop.
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
Terminate me by kill -TERM 90 | |
http://example.org trying to contact | |
http://softwearautomation.com trying to contact | |
http://example.org <!doctype html> | |
http://softwearautomation.com <!DOCTYPE html> | |
http://example.org trying to contact | |
http://example.org <!doctype html> | |
http://softwearautomation.com trying to contact | |
http://softwearautomation.com <!DOCTYPE html> | |
http://example.org trying to contact | |
http://example.org <!doctype html> | |
http://softwearautomation.com trying to contact | |
http://softwearautomation.com <!DOCTYPE html> | |
Exiting |
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 | |
import gevent.monkey | |
from contextlib import closing | |
gevent.monkey.patch_all() | |
import urllib | |
import signal | |
import os | |
INTERVAL = 10 | |
urls = ['http://example.org', 'http://softwearautomation.com'] | |
def sigterm_handler(workers): | |
for w in workers: | |
w.kill() | |
def worker(url): | |
while 1: | |
print url, 'trying to contact' | |
with closing(urllib.urlopen(url)) as fp: | |
line = fp.readline() | |
print url, line | |
gevent.sleep(INTERVAL) | |
def main(): | |
workers = [gevent.spawn(worker, u) for u in urls] | |
gevent.signal(signal.SIGTERM, sigterm_handler, workers) | |
import os | |
print "Terminate me by kill -TERM", os.getpid() | |
gevent.joinall(workers) | |
print "Exiting" | |
if __name__ == '__main__': | |
main() |
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 | |
import gevent.monkey | |
from contextlib import closing | |
gevent.monkey.patch_all() | |
import urllib | |
INTERVAL = 10 | |
urls = ['http://example.org', 'http://softwearautomation.com'] | |
def worker(url): | |
while 1: | |
print url, 'trying to contact' | |
with closing(urllib.urlopen(url)) as fp: | |
line = fp.readline() | |
print url, line | |
gevent.sleep(INTERVAL) | |
def main(): | |
workers = [gevent.spawn(worker, u) for u in urls] | |
gevent.joinall(workers) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment