Skip to content

Instantly share code, notes, and snippets.

@Pk13055
Forked from tvst/run_all.py
Created September 19, 2020 13:11
Show Gist options
  • Save Pk13055/a96bca24ba4bec25c619231f1b2555a3 to your computer and use it in GitHub Desktop.
Save Pk13055/a96bca24ba4bec25c619231f1b2555a3 to your computer and use it in GitHub Desktop.

Revisions

  1. @tvst tvst revised this gist Oct 8, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion run_all.py
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,6 @@ def signal_handler(signal_number, stack_frame):
    # Runs all Python files, but exclude this script to avoid a loop.

    this_file = os.path.abspath(__file__)
    print(this_file)

    for basename in os.listdir(folder):
    fname = os.path.join(folder, basename)
  2. @tvst tvst revised this gist Oct 5, 2019. No changes.
  3. @tvst tvst created this gist Oct 5, 2019.
    45 changes: 45 additions & 0 deletions run_all.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    import os
    import signal
    import subprocess
    import sys

    # Parse command-line arguments.
    if len(sys.argv) > 1:
    folder = os.path.abspath(sys.argv[1])
    else:
    folder = os.path.abspath(os.getcwd())

    # Set up a signal handler so we can stop all Streamlit instances with Ctrl-C.

    processes = []

    def signal_handler(signal_number, stack_frame):
    for process in processes:
    process.kill()

    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    if sys.platform == 'win32':
    signal.signal(signal.SIGBREAK, signal_handler)
    else:
    signal.signal(signal.SIGQUIT, signal_handler)


    # Runs all Python files, but exclude this script to avoid a loop.

    this_file = os.path.abspath(__file__)
    print(this_file)

    for basename in os.listdir(folder):
    fname = os.path.join(folder, basename)

    if fname.endswith('.py') and fname != this_file:
    process = subprocess.Popen(['streamlit', 'run', fname])
    processes.append(process)


    # Block this script until all processes terminate.

    for process in processes:
    process.wait()