comparison core/management/commands/ssl_images.py @ 898:8fcd278d8987

Add socket timeout option.
author Brian Neal <bgneal@gmail.com>
date Sat, 28 Feb 2015 14:35:47 -0600
parents 49ebeb54990a
children 62cd07bb891c
comparison
equal deleted inserted replaced
897:49ebeb54990a 898:8fcd278d8987
272 type='int', 272 type='int',
273 help="optional first slice index; the i in [i:j]"), 273 help="optional first slice index; the i in [i:j]"),
274 make_option('-j', '--j', 274 make_option('-j', '--j',
275 type='int', 275 type='int',
276 help="optional second slice index; the j in [i:j]"), 276 help="optional second slice index; the j in [i:j]"),
277 make_option('-t', '--timeout',
278 type='int',
279 help="optional socket timeout (secs)"),
277 ) 280 )
278 281
279 def handle_noargs(self, **options): 282 def handle_noargs(self, **options):
280 time_started = datetime.datetime.now() 283 time_started = datetime.datetime.now()
281 _setup_logging() 284 _setup_logging()
308 qs = qs[i:] 311 qs = qs[i:]
309 elif i is None and j is not None: 312 elif i is None and j is not None:
310 qs = qs[:j] 313 qs = qs[:j]
311 314
312 # Set global socket timeout 315 # Set global socket timeout
313 socket.setdefaulttimeout(30) 316 timeout = options.get('timeout', 30)
317 logger.info("Setting socket timeout to %d", timeout)
318 socket.setdefaulttimeout(timeout)
314 319
315 # Install signal handler for ctrl-c 320 # Install signal handler for ctrl-c
316 signal.signal(signal.SIGINT, signal_handler) 321 signal.signal(signal.SIGINT, signal_handler)
317 322
318 # Create URL opener to download photos 323 # Create URL opener to download photos