Python cronかコマンドライン実行か判別

Pythonスクリプトがcronから起動されたか、コマンドラインから起動されたかを区別する方法

import os
import sys

def is_cron_job():
    return (
        'SSH_TTY' not in os.environ and 
        sys.stdin.isatty() == False and 
        '--cron' in sys.argv
    )

if is_cron_job():
    print("This script was run by cron.")
else:
    print("This script was run from the command line.")