You could change your handler to read from a file given at the command line instead of stdin
:
#!/usr/bin/env python
import shutil
import sys
import time
print "In handler..."
with open(sys.argv[1], 'rb') as file:
shutil.copyfileobj(file, sys.stdout)
sys.stdout.flush()
time.sleep(5)
Then you could create a named pipe in main.py
, to send the data:
#!/usr/bin/env python
import os
from subprocess import Popen
fifo = "fifo"
os.mkfifo(fifo)
p = Popen(["gnome-terminal", "-x", "python", "handler.py", fifo])
with open(fifo, 'wb') as file:
file.write("Text sent to handler for display")
os.remove(fifo)
p.wait()