I have a script that takes a while to run, and I'm using screen to run it.ssh user@host screen -dm python dostuff.pyNow the question is, how do I make sure it kills the screen session after dostuff.py finishes execution? Whether it's because an error, or proper termination. 
Kill a screen session when script is done executing
gnu screen
This might be in the workaround category, but I was able to achieve what I think your goal is by putting the command (python dostuff.py from your example) into a shell script, then running ... screen -d -m /path/to/that/script Version info:$ screen -vScreen version 3.09.10 (FAU) 4-Sep-01Looks like I have a pretty old version of screen on this system! Perhaps screen's behavior changed in more recent versions to automatically exit?$ screen -lsNo Sockets found in /tmp/uscreens/S-username.$ screen -dm ls$ screen -lsThere is a screen on:        32112694.ls     (Detached)1 Socket in /tmp/uscreens/S-username.(screen -r; exit)$ screen -lsNo Sockets found in /tmp/uscreens/S-username.$ cat runme#!/bin/shsleep 6ls > now$ screen -d -m ./runme$ ps -ef|grep sleep username 9633926  9437204   0 14:55:23  pts/1  0:00 grep sleep username 15532242 10223670   0 14:55:21  pts/6  0:00 sleep 6(wait 6 seconds)$ screen -lsNo Sockets found in /tmp/uscreens/S-username.$ ls nownowOne thing I realized when going through this was that my version of screen seemed to expect a session name after -dm; I had to separate -d and -m in order to pass a command argument.Try using:ssh user@host screen -d -m python dostuff.pywith an optional -S to name the session something specific.