Python: Screen?

February 1st, 2008 § 10 comments

Here’s a ques­tion out of left-field. Any­one know of a Python util­ity that either uses/abuses the linux “screen” com­mand, or a library which mim­ics the func­tion­al­ity of screen?

The prob­lem I’ve got is some­thing like:
– load a shell
– load a bunch of envi­ron­ment stuff (mainly auth info)
– exe­cute long run­ning python appli­ca­tion which is log­ging to std­out
– detach from long run­ning appli­ca­tion, log out
– log back in, reattach

Now, yes — I could in the­ory fork a dae­mon process to do this — but the appli­ca­tion itself is user-interactive, so pick­ing it up/leaving it ala screen works exceed­ingly well. Not to men­tion the need to pull in authen­ti­ca­tion from the shell.

I could sim­ply tell the user “hey, use screen!” but I’d rather not have to deal with explain­ing to them the nuances of the key sequence: I’d rather auto­mate it all.

  • Jason Chu

    You can do that with screen. Cre­ate a cus­tom screenrc that spec­i­fies a cus­tom script (load a bunch of envi­ron­ment stuff, exe­cute long run­ning python appli­ca­tion) in the shell option and put at the very bot­tom the detach option.

    Then write an alias or shell script that exe­cutes screen –c <myscreenrc>

    When you first run it, it’ll start, set every­thing up, and then detach. After­wards you can reat­tach when­ever you please.

  • artyom

    Seems that dtach ( http://dtach.sourceforge.net ) is the thing you need.

  • ethel g

    detachtty (http://www.cliki.net/detachtty) does this — it was orig­i­nally writ­ten to inter­act with long-running Lisp processes, but doesn’t have any Lisp depen­den­cies as far as I know

  • Glyph

    You could use Twisted, and call spawn­Process with a PTY, and maybe attempt to do some of what screen does with twisted.conch.insults. The results would be pretty cool, but to be hon­est, you’d prob­a­bly end up doing a lot of work and need­ing to con­tribute some patches to Twisted to fill in some gaps — espe­cially in the area of insults (a clone of “curses”).

  • jnoller

    Some sick part of me thinks this would be a sim­ply jolly idea. Then cold, cold real­ity sets in. Although, I didn’t know twisted had a curses imple­men­ta­tion. I like the name :)

  • jnoller

    This is by far the sim­plest approach — I sort of wish I could do it inside of the appli­ca­tion though.

  • Hal

    PyEx­pect can be used as well to set this up. See <http://pexpect.sourceforge.net/>

  • http://jessenoller.com jnoller

    Some sick part of me thinks this would be a sim­ply jolly idea. Then cold, cold real­ity sets in. Although, I didn’t know twisted had a curses imple­men­ta­tion. I like the name :)

  • http://jessenoller.com jnoller

    This is by far the sim­plest approach — I sort of wish I could do it inside of the appli­ca­tion though.

  • Hal

    PyEx­pect can be used as well to set this up. See <http://pexpect.sourceforge.net/>

What's this?

You are currently reading Python: Screen? at jessenoller.com.

meta