File tree Expand file tree Collapse file tree 4 files changed +20
-9
lines changed Expand file tree Collapse file tree 4 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 8
8
9
9
from .consts import \
10
10
DATA_DIR , \
11
+ TMP_NODE , \
12
+ TMP_BACKUP , \
11
13
PG_CONF_FILE , \
12
14
BACKUP_LOG_FILE , \
13
15
DEFAULT_XLOG_METHOD
@@ -49,7 +51,7 @@ def __init__(self,
49
51
50
52
# Set default arguments
51
53
username = username or default_username ()
52
- base_dir = base_dir or tempfile .mkdtemp ()
54
+ base_dir = base_dir or tempfile .mkdtemp (prefix = TMP_BACKUP )
53
55
54
56
# public
55
57
self .original_node = node
@@ -96,7 +98,7 @@ def _prepare_dir(self, destroy):
96
98
available = not destroy
97
99
98
100
if available :
99
- dest_base_dir = tempfile .mkdtemp ()
101
+ dest_base_dir = tempfile .mkdtemp (prefix = TMP_NODE )
100
102
101
103
data1 = os .path .join (self .base_dir , DATA_DIR )
102
104
data2 = os .path .join (dest_base_dir , DATA_DIR )
Original file line number Diff line number Diff line change 7
7
8
8
from contextlib import contextmanager
9
9
10
+ from .consts import TMP_CACHE
11
+
10
12
11
13
class GlobalConfig (object ):
12
14
"""
@@ -101,6 +103,7 @@ def copy(self):
101
103
config_stack = []
102
104
103
105
106
+ @atexit .register
104
107
def rm_cached_initdb_dirs ():
105
108
for d in cached_initdb_dirs :
106
109
shutil .rmtree (d , ignore_errors = True )
@@ -161,8 +164,5 @@ def configure_testgres(**options):
161
164
testgres_config .update (options )
162
165
163
166
164
- # NOTE: to be executed at exit()
165
- atexit .register (rm_cached_initdb_dirs )
166
-
167
167
# NOTE: assign initial cached dir for initdb
168
- testgres_config .cached_initdb_dir = tempfile .mkdtemp ()
168
+ testgres_config .cached_initdb_dir = tempfile .mkdtemp (prefix = TMP_CACHE )
Original file line number Diff line number Diff line change 4
4
DATA_DIR = "data"
5
5
LOGS_DIR = "logs"
6
6
7
+ # prefixes for temp dirs
8
+ TMP_NODE = 'tgsn_'
9
+ TMP_CACHE = 'tgsc_'
10
+ TMP_BACKUP = 'tgsb_'
11
+
7
12
# names for config files
8
13
RECOVERY_CONF_FILE = "recovery.conf"
9
14
PG_AUTO_CONF_FILE = "postgresql.auto.conf"
Original file line number Diff line number Diff line change 23
23
from .consts import \
24
24
DATA_DIR , \
25
25
LOGS_DIR , \
26
+ TMP_NODE , \
26
27
PG_CONF_FILE , \
27
28
PG_AUTO_CONF_FILE , \
28
29
HBA_CONF_FILE , \
@@ -106,7 +107,9 @@ def __enter__(self):
106
107
def __exit__ (self , type , value , traceback ):
107
108
self .free_port ()
108
109
109
- got_exception = value is not None
110
+ # NOTE: ctrl+C does not count!
111
+ got_exception = type is not None and type != KeyboardInterrupt
112
+
110
113
c1 = self .cleanup_on_good_exit and not got_exception
111
114
c2 = self .cleanup_on_bad_exit and got_exception
112
115
@@ -152,8 +155,9 @@ def _try_shutdown(self, max_attempts):
152
155
except ExecUtilException :
153
156
pass # one more time
154
157
except Exception :
155
- # TODO: probably kill stray instance
158
+ # TODO: probably should kill stray instance
156
159
eprint ('cannot stop node {}' .format (self .name ))
160
+ break
157
161
158
162
attempts += 1
159
163
@@ -195,7 +199,7 @@ def _create_recovery_conf(self, username):
195
199
196
200
def _prepare_dirs (self ):
197
201
if not self .base_dir :
198
- self .base_dir = tempfile .mkdtemp ()
202
+ self .base_dir = tempfile .mkdtemp (prefix = TMP_NODE )
199
203
200
204
if not os .path .exists (self .base_dir ):
201
205
os .makedirs (self .base_dir )
You can’t perform that action at this time.
0 commit comments