Multiple canvas on Windows with python

Dear all

I tried to run simple python script on Windows with ROOT 6.26.02 and python 3.8.10 and noticed that I can not create more than two canvas. Python simply hangs when 3rd canvas is created. Is it known feature ?
Code is given below and input file can be found in ~solodkov/public/pyroot on AFS at CERN

########### cut here ###################

import os,sys
if os.name == 'nt':
  sys.path.append(r'C:\root_v6.26.02\bin')

import ROOT

ncanvas = 4
timesleep = 5

inputfile = 'cs11828.root'
print('Opening %s' % inputfile)
file = ROOT.TFile(inputfile)
file.cd("RawData")

ps_names=['10A','14A','18A','22A','46A','50A','34A','54A']

cc = []
adc = []
for i in range(ncanvas):
    adcname = 'Cs.ADC.%s' % ps_names[i]
    print('Looking for %s' % adcname)
    adc += [ROOT.gDirectory.Get(adcname)]
    nm = "c%d" % (i+1)
    cc += [ROOT.TCanvas(nm,nm,50*i,50*i,800,600)]
    adc[i].Draw('value')
    cc[i].Update()

if timesleep>0:
    import time
    print('Sleeping %d sec' % timesleep)
    time.sleep(timesleep)

###################### cut here ##########################


ROOT Version: 6.26.02
Platform: Windows
Compiler: Not Provided


On WSL, without your file and only opening (but not using) hsimple.root, these lines work, creating 4 empty canvases:

import os,sys
if os.name == 'nt':
  sys.path.append(r'C:\root_v6.26.02\bin')

import ROOT

ncanvas = 4
timesleep = 5

inputfile = 'hsimple.root'
print('Opening %s' % inputfile)
file = ROOT.TFile(inputfile)

ps_names=['10A','14A','18A','22A','46A','50A','34A','54A']

cc = []
adc = []
for i in range(ncanvas):
    adcname = 'Cs.ADC.%s' % ps_names[i]
    print('Looking for %s' % adcname)
    nm = "c%d" % (i+1)
    cc += [ROOT.TCanvas(nm,nm,50*i,50*i,800,600)]
    print('nm = %s' % nm)

if timesleep>0:
    import time
    print('Sleeping %d sec' % timesleep)
    time.sleep(timesleep)

Maybe the problem is with your root file, maybe it does not contain some of the objects you are trying to get, or there is a problem drawing them. Try checking that.

Thanks for reply!
But I have the same problem with your macro
What I did exactly is the following:

  1. On fresh Windows 10 computer (in CERN domain) installed Visual Studio Community 2022 with python 3.9.7 (they come together)
  2. installed ROOT 6.26.02
  3. figured out that ROOT requires python 3.8 - removed python 3.9, took python 3.8.10 from python.org and installed it
  4. ran macro “python check.py” and got “Python not responding” when 3rd canvas is created, doesn’t matter what is inside this canvas

Repeated the same steps on another computer with Visual Studio 2019 and got the same results

This is a known issue. The GUI event loop is not handled correctly in Python on Windows.

Naive question - maybe it’s handled better in recent versions of python ?
Is it possible to use python 3.9 or 3.10 without recompiling whole ROOT ?

No, the problem is on ROOT side

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.