Run Codes in the Background in Server

To use screen to run ./race_full.py in one session and ./race_last.py in another, here’s how you can do it:

  1. Start a New Screen Session for race_full.py:

    • Create and name the session for race_full.py:

      screen -S session_name
    • Inside this screen session, run the script:

      ./race_full.py
    • Detach from the session by pressing Ctrl+A``D. This will keep race_full.py running in the background.

  2. Start Another Screen Session for race_last.py:

    • Create and name the session for race_last.py:

      screen -S  session_name
    • Inside this screen session, run the script:

      ./race_last.py
    • Detach from this session as well using Ctrl+A then D.

  3. Check and Manage Screen Sessions:

    • To view your active sessions, use:

      screen -ls
    • You should see both race_full and race_last listed, either as (Attached) or (Detached).

  4. Reattach to a Session:

    • If you want to reattach to a session, specify its name. For example:

      ,race_full
    • To reattach to race_last:

      screen -r race_last

This setup will keep both scripts running independently, and you can freely detach and reattach as needed to monitor their progress.