2

Hi I've been struggling to sort out an issue with some of my thesis code for a couple of days. What I'm trying to do is run a python code within screen via a command in Putty via:

    $ screen ./Top.py

Top.py is a dummy code I made to try and sort this out rather than waiting eight hours for the real code to hit the error. The issue that it encounters is that subprocess.call() it cannot begin new screens from a detached screen.

Contents of Top.py:

    #!/usr/bin/env python

    import time
    import subprocess

    time.sleep(10)

    subprocess.call(["screen", "nohup", "./Call1.py", "&"])
    subprocess.call(["screen", "nohup", "./Call2.py", "&"])
    time.sleep(10)

There aren't any issues with the Call1.py and Call2.py, and the whole code runs smoothly if I never detach the screen. (But the full code will take a couple of days, so I can't leave it attached.) Another note is the nohup is just there so I can get the nohup.out file to for later reference, my actual code changes the directory they are located in so they don't overwrite each other.

I don't have any issues with not using screen to run the Call1 & Call2, but they need to run in parallel and in the background so the rest of my code can continue.

Closest to a solution I have come - I think.....

  • A few days of frustration and within 10 minutes of posting I find a solution, a huge thanks to Gilles with the response here: [link](http://stackoverflow.com/questions/6064548/send-commands-to-a-gnu-screen?rq=1) I believe it may actually have been a solution I attempted earlier, but somehow failed in my coding of the subprocess.call() – Morgan Meeuwissen Aug 30 '13 at 01:41
  • Ok, that earlier solution was a false alarm that worked for my test code but not my real code. In the end I solve the issue by swapping to subprocess.popen instead of subprocess.call thus eliminating the need for the ugly use of additional screens. – Morgan Meeuwissen Aug 30 '13 at 05:46

0 Answers0