Inconsistent TCanvas function in PyRoot

Running on Windows XP (SP3) on Toshiba Satellite pro.
Python 2.5.4
Eclipse 20090920

This is a modified example from the Root Python documentation
ftp://root.cern.ch/root/doc/19PythonRuby.pdf

Below is a code sample which demonstrates inconsistent behaviour of the PyRoot call to TCanvas.
There are 2 lines with ‘c1=TCanvas…’
Run the version below (with the second call to TCanvas commented out)and only 5 calls to the ‘print index’ are displayed in the Eclipse ouput window, then a Root blank canvas window is displayed. Then the program hangs.

Now coment out the first version of c1=TCanvas… and remove the comment # from the second call to c1=TCanvas…
Now when you run all 25000 ‘print index’ values are displayed in the Eclipse output window and the Root canvas window is displayed correctly with the appropriate values in the histogram.

The second version confirms the paths etc are valid and the overall system is correctly configured.
I have checked on a colleague’s machine and both versions of the code work on an Apple Mac & a Linux (CERN Scientific) PC, so this appears to be restricted to Windows.

Expected behaviour: Root should give the same result with either call to TCanvas().


‘’’
Created on 2 Nov 2009

@author: Tony Poll
‘’’
from ROOT import gRandom,TCanvas,TH1F #@UnresolvedImport

Placing the call the TCanvas here does not work. Graph is never displayed

c1 = TCanvas(‘c1’,‘Example’,200,10,700,500)

hpx = TH1F(‘hpx’,‘px’, 100, -4, 4)
for index in xrange(25000):
print index
px = gRandom.Gaus()
hpx.Fill(px)

Placing the call the TCanvas here works

#c1 = TCanvas(‘c1’,‘Example’,200,10,700,500)
hpx.Draw()
c1.Update()
graph.py (482 Bytes)

Hi,

You didn’t say whether you were running gcc or VC++ root. With gcc, it works fine. If I don’t run python interactively, I only see the window flash before the program ends.

cplager@Hagrid> python -i graph.py 

Cheers,
Charles

1 Like

I’m running gcc. This was installed with Cygwin, version 1.5.25-15
Just to make sure - in the situation I reported as a bug: I only see the first 3 or 4 values of the variable ‘index’ and then the application hangs. (In Task Manager I get the ‘Not Responding’ status.)
However you see all 2,500 counts displayed?

[quote=“tonypoll”]I’m running gcc. This was installed with Cygwin, version 1.5.25-15
Just to make sure - in the situation I reported as a bug: I only see the first 3 or 4 values of the variable ‘index’ and then the application hangs. (In Task Manager I get the ‘Not Responding’ status.)
However you see all 2,500 counts displayed?[/quote]

Yep, all 2,500 counts and the plot. If I don’t run interactively, I still see all 2500 counts and a window flashing. I’m running 5.20/00

Cheers,
Charles

Hi,

there’s a (by now ancient) pb where changes in how OS events were handled and propagated by ROOT hangs up the two threads (for GUI and CLI respectively) used by python. Since the pb is a race condition, the behavior is erratic. I’ve been talking to the Windows experts for a while, but have had no solution yet.

Cheers,
Wim