Skip to content
Browse files

better signal handling for consume.py

  • Loading branch information...
1 parent ffff384 commit d43b87eeb8d1e65297ed6c1e9fddb95ad34240df @barberdt barberdt committed Dec 5, 2011
Showing with 11 additions and 2 deletions.
  1. +10 −0 consume.py
  2. +1 −2 produce.py
View
10 consume.py
@@ -4,13 +4,22 @@
import sys
import httplib
import os
+import signal
+
+conn = None
def usage(script_name):
print "%s [consume] \n"%(script_name)
print "Use '%s [method] --help' for a method's usage and options."%(script_name)
sys.exit()
+def signal_handler(signal, frame):
+ global conn
+ conn.close()
+ sys.exit(0)
+
def consume(hostname, api_key, swarm_id, resource_id):
+ global conn
conn = httplib.HTTPConnection(hostname)
conn.request("GET", "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id), None, {"x-bugswarmapikey":api_key})
resp = conn.getresponse()
@@ -26,6 +35,7 @@ def main():
if len(sys.argv) == 1:
usage(sys.argv[0])
elif sys.argv[1] == "consume":
+ signal.signal(signal.SIGINT, signal_handler)
opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID"%(sys.argv[1])
opt_usage += "\n\n *SWARM_ID: The ID of the swarm to consume." \
+"\n *RESOURCE_ID: The ID of the resource to use for consumption."
View
3 produce.py
@@ -16,8 +16,7 @@ def usage(script_name):
def signal_handler(signal, frame):
global conn
- conn.close()
- print 'Http connection closed.'
+ conn.close()
sys.exit(0)
def produce(hostname, api_key, swarm_id, resource_id, wrap):

0 comments on commit d43b87e

Please sign in to comment.
Something went wrong with that request. Please try again.