Spaces:
Sleeping
Sleeping
Update status_checker.py
Browse files- status_checker.py +13 -2
status_checker.py
CHANGED
|
@@ -5,9 +5,10 @@ import gradio as gr
|
|
| 5 |
from huggingface_hub import upload_folder, HfFolder, delete_repo
|
| 6 |
import sys
|
| 7 |
import time
|
|
|
|
| 8 |
from huggingface_hub.utils import logging
|
| 9 |
|
| 10 |
-
|
| 11 |
logger = logging.get_logger(__name__)
|
| 12 |
|
| 13 |
HfFolder().save_token(os.getenv("HF_TOKEN"))
|
|
@@ -16,8 +17,17 @@ output_dataset_id = "nateraw/asdf123"
|
|
| 16 |
# Where user will write outputs from their script
|
| 17 |
outputs_dir = Path('outputs')
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
# A file that marks that the script has finished running
|
| 22 |
# TODO - maybe check process like this instead of with done.txt: https://stackoverflow.com/a/2944076
|
| 23 |
output_file = Path('done.txt')
|
|
@@ -25,6 +35,7 @@ output_file = Path('done.txt')
|
|
| 25 |
def status_checker():
|
| 26 |
logger.info("Waiting to find output_file to check if script is done running")
|
| 27 |
while True:
|
|
|
|
| 28 |
if output_file.exists():
|
| 29 |
logger.info("Found the output file - Uploading the outputs from the script")
|
| 30 |
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
|
|
|
|
| 5 |
from huggingface_hub import upload_folder, HfFolder, delete_repo
|
| 6 |
import sys
|
| 7 |
import time
|
| 8 |
+
import subprocess
|
| 9 |
from huggingface_hub.utils import logging
|
| 10 |
|
| 11 |
+
logging.set_verbosity_info()
|
| 12 |
logger = logging.get_logger(__name__)
|
| 13 |
|
| 14 |
HfFolder().save_token(os.getenv("HF_TOKEN"))
|
|
|
|
| 17 |
# Where user will write outputs from their script
|
| 18 |
outputs_dir = Path('outputs')
|
| 19 |
|
| 20 |
+
process_pid = os.getenv('USER_SCRIPT_PID', None)
|
| 21 |
+
logger.info(f"USER SCRIPT PID? - {process_pid} - type {type(process_pid)}")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def process_is_complete():
|
| 25 |
+
# Attempt at solving the todo shown below
|
| 26 |
+
p = subprocess.Popen(['ps', '-p', process_pid], stdout=subprocess.PIPE)
|
| 27 |
+
out = p.communicate()[0].decode('utf-8').strip().split('\n')
|
| 28 |
+
return len(out) == 1
|
| 29 |
|
| 30 |
+
|
| 31 |
# A file that marks that the script has finished running
|
| 32 |
# TODO - maybe check process like this instead of with done.txt: https://stackoverflow.com/a/2944076
|
| 33 |
output_file = Path('done.txt')
|
|
|
|
| 35 |
def status_checker():
|
| 36 |
logger.info("Waiting to find output_file to check if script is done running")
|
| 37 |
while True:
|
| 38 |
+
logger.info(f"Process is complete? {process_is_complete()}")
|
| 39 |
if output_file.exists():
|
| 40 |
logger.info("Found the output file - Uploading the outputs from the script")
|
| 41 |
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
|