Hi,
I would like to run a PyRoot process in the background that gives me a TBrowser. All the following examples run fine when called as$>python script.pyThe problems only show up when using$>python script.py &The following script runs fine when started normally:
import ROOT,time,sys
infiles=[ROOT.TFile.Open(name) for name in sys.argv[1:]]
tbrowse=ROOT.TBrowser()
while tbrowse:
time.sleep(1)
However, if I start it as a background process it gets stopped somehow.
I have been able to reduce the problem to the following:
This runs (and keeps messing with my command line):
import time
while 1:
time.sleep(1)
print "Still here"
This doesn’t run and get’s stopped immediately:
import time, ROOT
while 1:
time.sleep(1)
print "Still here"
If you can’t reproduce the problem then it’s probably specific to OSX (maybe I should have mentioned that I’m running on mac).
However, I don’t see why the background-ness should stop the process from displaying graphics. In my understanding running something in the background merely means that it isn’t attached to my terminal, after all that’s exactly how I start emacs and other programs from the command line.
no, I’m running on a Mac as well, so I don’t think that’s it. Also, the background process isn’t detached in your case, or it would not be able to print to the terminal … As for emacs, it’s programmed to behave that way: if you run it with -nw it’ll get suspended just as much as it is expecting stdout at that point. Of course, if you don’t actually care about the terminal at all, simply close stdin/out and from there things should work. You can either do that explicitly in python, but best is not to have any terminal stdout/in in the first place, so execute from the shell in a way that does not open them:$ python < script.py &
Cheers,
Wim
Ok, your suggestion worked. But since I still want to use other command line options I’m actually doing
os.close(0) #closes stdin at the C-levelbofore importing ROOT.
This fixes it. I now have nice script called rootbrowse which can run in the background. Here it is if anyone is interested:[code]import os, sys, time
def main():
os.close(0) #close stdin
import ROOT
infiles=[ROOT.TFile.Open(name) for name in sys.argv[1:]]
tbrowse=ROOT.TBrowser()
try:
while tbrowse:
time.sleep(1)
except KeyboardInterrupt,e:
print ""