0

I wrote a python script. When I run it directly(like below) it works fine.

python check_C1_criteria_file.py > test.out

But when I run it in background(like below) it neither shows any result nor error.

python check_C1_criteria_file.py > test.out &

or

nohup python check_C1_criteria_file.py &

What can go wrong? Can anyone help me with this?

Update:

The main part of the script is as follow:

 blastOutput_file=sys.argv[1];
 lengthFile = sys.argv[2];
 with open(blastOutput_file, 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter='\t')
    sys.stdout.write('#query_id'+'\t'+'Mapping_Id'+'\t'+'Description'+'\n');
    for row in reader:
        tid=row[0];
        subid=row[1];
        mapid=getMapping_id(subid);
        idDes = search_id(lengthFile, mapid);
        if idDes is not None:
            sys.stdout.write(tid+'\t'+str(mapid)+'\t'+str(idDes)+'\n');

Am I missing something?

2
  • 2
    It sounds like you can run a python program in the background. Do you still want to see the log? Try using nohup python check_C1_criteria_file.py > file.log & Commented Mar 10, 2015 at 4:20
  • 2
    Throw in some sys.stdout.flush()'s after your prints or use the logging module. Does it still not output? Commented Mar 10, 2015 at 4:36

2 Answers 2

1

Is your script doing any sort of terminal handling? Does it do any I/O other than simple sys.stdout.write() or calls to print (Python2.x) or print() (Python3.x)? Is it performing any input() or raw_input() or sys.stdin.read() operations? Is it Python 2 or 3?

Roughly speaking the only sorts of things which differ when running a command in the background vs. in the foreground are those related to any calls it makes to your terminal. A process in the background attempting to access your terminal may be put to sleep until its brought back into the foreground. Normal writes to stdout will not block ... but any calls to curses functions, even some of the termio stuff in getpass() might set the terminal into a mode that will block on attempted terminal writes.

Sign up to request clarification or add additional context in comments.

Comments

0

You can try

nohup python check_C1_criteria_file.py >test.out 2>&1 &

You had better examine that this program terminated normally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.