Search code examples
screen

Can't run a python file in a detached screen


I am trying to run several python files in screens, starting the screens within a for loop in bash. The screens should not start attached so that the for loop can continue without the python file needing to be finished. I've found online, e.g. through this answer that something like screen -dmS "python3 test.py" should work; however, all this does for me is create the screen with the name "python3 test.py", and when I attach the screen I can see that nothing is running.

test.py is a file I created which contains

import time
time.sleep(10000)

the real script I want to use is an ML file so I could also see this was not working as intended as my GPU ended up with no jobs on it.

Could someone please explain why this is not working -- I have tried this both on my Linux (ubuntu) machine and Mac, both do the same.


Solution

  • -S is the flag for session name (man 1 screen).

    You can run your script detached with screen -S test -dm python3 test.py.

    Edit: the command and parameter don't need to be put in a string.