Allow run_line_magic to be called from scripts

Don't blow up if looking back up the stack trace fails.

Reported on rpy2: https://bitbucket.org/lgautier/rpy2/issue/184
/valueerror-call-stack-is-not-deep-enough
Merge pull request #6965 from takluyver/var-expand-locals-softfail

Allow run_line_magic to be called from scripts