Skip to content

Commit f32b529

Browse files
committed
Fix pylint
1 parent 77b39b3 commit f32b529

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/sagemaker/modules/train/container_drivers/mpi_utils.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,13 @@ def missing_host_key(self, client, hostname, key):
106106
def _can_connect(host: str, port: int = DEFAULT_SSH_PORT) -> bool:
107107
"""Check if the connection to the provided host and port is possible."""
108108
try:
109-
import paramiko
110-
111109
logger.debug("Testing connection to host %s", host)
112-
client = paramiko.SSHClient()
113-
client.load_system_host_keys()
114-
client.set_missing_host_key_policy(CustomHostKeyPolicy())
115-
client.connect(host, port=port)
116-
client.close()
117-
logger.info("Can connect to host %s", host)
118-
return True
110+
with paramiko.SSHClient() as client:
111+
client.load_system_host_keys()
112+
client.set_missing_host_key_policy(CustomHostKeyPolicy())
113+
client.connect(host, port=port)
114+
logger.info("Can connect to host %s", host)
115+
return True
119116
except Exception as e: # pylint: disable=W0703
120117
logger.info("Cannot connect to host %s", host)
121118
logger.debug(f"Connection failed with exception: {e}")
@@ -211,9 +208,9 @@ def validate_smddpmprun() -> bool:
211208

212209
def write_env_vars_to_file():
213210
"""Write environment variables to /etc/environment file."""
214-
with open("/etc/environment", "a") as f:
211+
with open("/etc/environment", "a", encoding="utf-8") as f:
215212
for name in os.environ:
216-
f.write("{}={}\n".format(name, os.environ.get(name)))
213+
f.write(f"{name}={os.environ.get(name)}\n")
217214

218215

219216
def get_mpirun_command(

0 commit comments

Comments
 (0)