zephyr_mirror: Use select to determine whether new messages are available.
(imported from commit a91f45aa9f3913f38285c050e574bf562b2af2df)
This commit is contained in:
parent
5a0e86c6d4
commit
fcb6336642
|
@ -38,6 +38,7 @@ import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
import tempfile
|
import tempfile
|
||||||
import random
|
import random
|
||||||
|
import select
|
||||||
|
|
||||||
class CountingBackoff(object):
|
class CountingBackoff(object):
|
||||||
def __init__(self, maximum_retries=10):
|
def __init__(self, maximum_retries=10):
|
||||||
|
@ -262,9 +263,9 @@ def maybe_restart_mirroring_script():
|
||||||
|
|
||||||
def process_loop(log):
|
def process_loop(log):
|
||||||
restart_check_count = 0
|
restart_check_count = 0
|
||||||
sleep_count = 0
|
last_check_time = time.time()
|
||||||
sleep_time = 0.1
|
|
||||||
while True:
|
while True:
|
||||||
|
select.select([zephyr._z.getFD()], [], [], 15)
|
||||||
try:
|
try:
|
||||||
notice = zephyr.receive(block=False)
|
notice = zephyr.receive(block=False)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -278,22 +279,19 @@ def process_loop(log):
|
||||||
logger.exception("Error relaying zephyr:")
|
logger.exception("Error relaying zephyr:")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
try:
|
if time.time() - last_check_time > 15:
|
||||||
maybe_restart_mirroring_script()
|
last_check_time = time.time()
|
||||||
if restart_check_count > 0:
|
try:
|
||||||
logging.info("Stopped getting errors checking whether restart is required.")
|
maybe_restart_mirroring_script()
|
||||||
restart_check_count = 0
|
if restart_check_count > 0:
|
||||||
except Exception:
|
logging.info("Stopped getting errors checking whether restart is required.")
|
||||||
if restart_check_count < 5:
|
restart_check_count = 0
|
||||||
logger.exception("Error checking whether restart is required:")
|
except Exception:
|
||||||
restart_check_count += 1
|
if restart_check_count < 5:
|
||||||
|
logger.exception("Error checking whether restart is required:")
|
||||||
|
restart_check_count += 1
|
||||||
|
|
||||||
time.sleep(sleep_time)
|
|
||||||
sleep_count += sleep_time
|
|
||||||
if sleep_count > 15:
|
|
||||||
sleep_count = 0
|
|
||||||
if options.forward_class_messages:
|
if options.forward_class_messages:
|
||||||
# Ask the Humbug server about any new classes to subscribe to
|
|
||||||
try:
|
try:
|
||||||
update_subscriptions()
|
update_subscriptions()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in a new issue