##// END OF EJS Templates
cache-keys: fix inifinite look of using atexit with signals....
super-admin -
r4853:5793cdd5 default
parent child Browse files
Show More
@@ -19,22 +19,37 b''
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import os
22 import sys
22 23 import atexit
23 24 import logging
24 25 import signal
26 import rhodecode
25 27
26 28 log = logging.getLogger(__name__)
27 29
28 30 cache_keys_by_pid = set()
29 31
30 32
33 def sigHandler(signo, frame):
34 """
35 signals trigger sys.exit so there's a single handler to cleanup the code.
36 """
37 if rhodecode.is_test:
38 return
39
40 sys.exit(0)
41
42
31 43 def free_cache_keys(*args):
44 from rhodecode.model.db import Session, CacheKey
45
46 if rhodecode.is_test:
47 return
48
32 49 ssh_cmd = os.environ.get('RC_CMD_SSH_WRAPPER')
33 50 if ssh_cmd:
34 51 return
35 52
36 from rhodecode.model.db import Session, CacheKey
37
38 53 if cache_keys_by_pid:
39 54 try:
40 55 for cache_proc in set(cache_keys_by_pid):
@@ -48,7 +63,8 b' def free_cache_keys(*args):'
48 63 except Exception:
49 64 log.exception('Failed to clear keys, exiting gracefully')
50 65
66 atexit.register(free_cache_keys)
51 67
52 atexit.register(free_cache_keys)
53 signal.signal(signal.SIGTERM, free_cache_keys)
54 signal.signal(signal.SIGINT, free_cache_keys)
68 signal.signal(signal.SIGTERM, sigHandler)
69 signal.signal(signal.SIGINT, sigHandler)
70
General Comments 0
You need to be logged in to leave comments. Login now