run python script in background

I am having problems starting a python script in rc.local. Looking into the problem it looks as if I am not even able to launch my script in the background.

My very simple python script called test.py contains:

#!/usr/bin/python
import sys
import time

while True:
    print "Hoi"
    time.sleep(1)

When on the Linino command line I do:

./test.py > /tmp/a.log

I see the file a.log in /tmp being created and filled, but it 'consumes' my terminal.

When I do:

./test.py > /tmp/x.log &

I can see (using top) that the test.py process is running. However, the file /tmp/x.log remains empty (it does get created). Also after killing the test.py process the file is still empty.

Any idea what I am doing wrong?

When I added sys.stdout.flush() after the print it seemed to work just fine. Is this as expected?

NewLine:
When I added sys.stdout.flush() after the print it seemed to work just fine. Is this as expected?

Yes, as the redirection output by default is buffered...

Using an occasional flush() as you already tried is the only reliable way to work around this, AFAIK...

Ralf