18
18
import boto3
19
19
import numpy
20
20
import pytest
21
- import tests .integ .local_mode_utils as local_mode_utils
21
+ import tempfile
22
+
23
+ import tests .integ .lock as lock
22
24
from tests .integ import DATA_DIR , PYTHON_VERSION
23
25
from tests .integ .timeout import timeout
24
26
25
27
from sagemaker .local import LocalSession , LocalSagemakerRuntimeClient , LocalSagemakerClient
26
28
from sagemaker .mxnet import MXNet
27
29
from sagemaker .tensorflow import TensorFlow
28
30
31
+ # endpoint tests all use the same port, so we use this lock to prevent concurrent execution
32
+ LOCK_PATH = os .path .join (tempfile .gettempdir (), 'sagemaker_test_local_mode_lock' )
29
33
DATA_PATH = os .path .join (DATA_DIR , 'iris' , 'data' )
30
34
DEFAULT_REGION = 'us-west-2'
31
35
@@ -101,7 +105,7 @@ def test_tf_local_mode(tf_full_version, sagemaker_local_session):
101
105
print ('job succeeded: {}' .format (estimator .latest_training_job .name ))
102
106
103
107
endpoint_name = estimator .latest_training_job .name
104
- with local_mode_utils .lock ():
108
+ with lock .lock (LOCK_PATH ):
105
109
try :
106
110
json_predictor = estimator .deploy (initial_instance_count = 1 ,
107
111
instance_type = 'local' ,
@@ -140,7 +144,7 @@ def test_tf_distributed_local_mode(sagemaker_local_session):
140
144
141
145
endpoint_name = estimator .latest_training_job .name
142
146
143
- with local_mode_utils .lock ():
147
+ with lock .lock (LOCK_PATH ):
144
148
try :
145
149
json_predictor = estimator .deploy (initial_instance_count = 1 ,
146
150
instance_type = 'local' ,
@@ -178,7 +182,7 @@ def test_tf_local_data(sagemaker_local_session):
178
182
print ('job succeeded: {}' .format (estimator .latest_training_job .name ))
179
183
180
184
endpoint_name = estimator .latest_training_job .name
181
- with local_mode_utils .lock ():
185
+ with lock .lock (LOCK_PATH ):
182
186
try :
183
187
json_predictor = estimator .deploy (initial_instance_count = 1 ,
184
188
instance_type = 'local' ,
@@ -217,7 +221,7 @@ def test_tf_local_data_local_script():
217
221
print ('job succeeded: {}' .format (estimator .latest_training_job .name ))
218
222
219
223
endpoint_name = estimator .latest_training_job .name
220
- with local_mode_utils .lock ():
224
+ with lock .lock (LOCK_PATH ):
221
225
try :
222
226
json_predictor = estimator .deploy (initial_instance_count = 1 ,
223
227
instance_type = 'local' ,
@@ -241,7 +245,7 @@ def test_local_mode_serving_from_s3_model(sagemaker_local_session, mxnet_model,
241
245
s3_model .sagemaker_session = sagemaker_local_session
242
246
243
247
predictor = None
244
- with local_mode_utils .lock ():
248
+ with lock .lock (LOCK_PATH ):
245
249
try :
246
250
predictor = s3_model .deploy (initial_instance_count = 1 , instance_type = 'local' )
247
251
data = numpy .zeros (shape = (1 , 1 , 28 , 28 ))
@@ -255,7 +259,7 @@ def test_local_mode_serving_from_s3_model(sagemaker_local_session, mxnet_model,
255
259
def test_local_mode_serving_from_local_model (tmpdir , sagemaker_local_session , mxnet_model ):
256
260
predictor = None
257
261
258
- with local_mode_utils .lock ():
262
+ with lock .lock (LOCK_PATH ):
259
263
try :
260
264
path = 'file://%s' % (str (tmpdir ))
261
265
model = mxnet_model (path )
@@ -285,7 +289,7 @@ def test_mxnet_local_mode(sagemaker_local_session, mxnet_full_version):
285
289
mx .fit ({'train' : train_input , 'test' : test_input })
286
290
endpoint_name = mx .latest_training_job .name
287
291
288
- with local_mode_utils .lock ():
292
+ with lock .lock (LOCK_PATH ):
289
293
try :
290
294
predictor = mx .deploy (1 , 'local' , endpoint_name = endpoint_name )
291
295
data = numpy .zeros (shape = (1 , 1 , 28 , 28 ))
@@ -310,7 +314,7 @@ def test_mxnet_local_data_local_script(mxnet_full_version):
310
314
mx .fit ({'train' : train_input , 'test' : test_input })
311
315
endpoint_name = mx .latest_training_job .name
312
316
313
- with local_mode_utils .lock ():
317
+ with lock .lock (LOCK_PATH ):
314
318
try :
315
319
predictor = mx .deploy (1 , 'local' , endpoint_name = endpoint_name )
316
320
data = numpy .zeros (shape = (1 , 1 , 28 , 28 ))
@@ -365,7 +369,7 @@ def test_local_transform_mxnet(sagemaker_local_session, tmpdir, mxnet_full_versi
365
369
transformer = mx .transformer (1 , 'local' , assemble_with = 'Line' , max_payload = 1 ,
366
370
strategy = 'SingleRecord' , output_path = output_path )
367
371
368
- with local_mode_utils .lock ():
372
+ with lock .lock (LOCK_PATH ):
369
373
transformer .transform (transform_input , content_type = 'text/csv' , split_type = 'Line' )
370
374
transformer .wait ()
371
375
0 commit comments