Last active
January 29, 2024 14:05
-
-
Save kirill-fedyanin/d341a9184e7bf123ab187f500571c045 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sudo apt install sox -y | |
import os | |
from argparse import ArgumentParser | |
from time import sleep | |
import boto3 | |
parser = ArgumentParser() | |
parser.add_argument('--instance-name', default='a100-kirill-2') | |
args = parser.parse_args() | |
sagemaker = boto3.client("sagemaker") | |
response = sagemaker.list_notebook_instances() | |
names = [r['NotebookInstanceName'] for r in response['NotebookInstances']] | |
if args.instance_name not in names: | |
raise ValueError(f"{args.instance_name} is not a valid instance name in this region, the correct are {names}") | |
for _ in range(100): | |
status = sagemaker.describe_notebook_instance(NotebookInstanceName=args.instance_name)['NotebookInstanceStatus'] | |
if status == 'InService': | |
print("Hooray, LGTM, it looks like it's up and running, let's gooooooo") | |
duration = 1 # seconds | |
freq = 240 # Hz | |
os.system('play -nq -t alsa synth {} sine {}'.format(duration, freq)) | |
os.system('play -nq -t alsa synth {} sine {}'.format(duration, 2*freq)) | |
os.system('play -nq -t alsa synth {} sine {}'.format(duration, freq)) | |
os.system('play -nq -t alsa synth {} sine {}'.format(duration, 0.5*freq)) | |
break | |
elif status == 'Pending': | |
print("Waiting...") | |
sleep(10) | |
elif status == 'Stopped' or status == 'Failed': | |
print(f"It's {status}, will try to relaunch") | |
sagemaker.start_notebook_instance(NotebookInstanceName=args.instance_name) | |
sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment