Crash calling gClient.GetRoot() with PyROOT

Dear Experts,
I’m attaching a simple PyROOT program using “TGMainFrame”.
Unfortunately it crashes at the instruction:
gClient.GetRoot()
and I’m not able to figure out why.

I’m using MAC OS: 10.12.1
ROOT: root_v6.06.08

Many thanks for your support.

Hi Mauro,

this is still not reproducible as some input arguments are needed. Could you provide a correct invocation of the script?

Cheers,
D

Hi,
Many thanks for looking into this.

This is a very simple script that I wrote as “template” for my future code development.
The parameters are not really used in the code.

You can call the script with:
python TestPyROOT.py -i in -o out

Many thanks,

  • Mauro.

Hi Mauro,

I can reproduce the issue: I’ll look into it and come back to you with some more details.
For the time being, you can continue prototyping replacing the expression:

gClient.GetRoot()

with

ROOT.TGClient.Instance().GetRoot()

Cheers,
Danilo

1 Like

Many thanks.
that works nicely.

Ciao,

  • Mauro.
1 Like

Hi, it’s me again.
Now the program (here in attachment) is working but somehow it’s not doing what I was hoping.

I thought I could have an “alive” window while doing other things.
For example in the program I instantiate the window and then I start an infinite loop that prints number on the screen.

I was hoping that while it was printing the numbers I could access the window (at the same time), but actually It’s not doing that. While it prints the numbers I can not access the window.

Do you know whether there is an error in my program or the “ROOT Window Manager” is not supposed to work that way I described?

Many thanks again.

You need a TThread. Take a look at:

Hi again :frowning:
I think I understood your example, though I’m not sure how to implement it in my case.
I’ve tried to “thread” TGMainFrame.init but apparently it’s not working.
(I’m attaching the usual example)

Can you please give me an hint on how to implement it in my case ?
Many thanks,

Why do you want to thread the init function?

I think you rather thread the “iteration function”

def filler_function(argv = None):
    it = 0
    while (True):
        print "It: ", it
        it += 1
        sleep(0.1)
        
        
        (...)
 
    myWindow = myGui(TGClient.Instance().GetRoot(),800,500)
    myWindow.myHisto = TF1('funMyWindow', 'abs(sin(x)/x)', 0, 10)
    myWindow.drawHisto()

    myThread = TThread("myThread",filler_function)
    myThread.Run()

I do not know how to call this correctly from pyroot, sorry.

Hi,
many thanks for the suggestion, but with this simple test:

def filler_function(argv = None):
it = 0

myThread = TThread(“myThread”,filler_function)
myThread.Run()

I get the error:

Traceback (most recent call last):
File “TestPyROOT.py”, line 191, in
sys.exit(main())
File “TestPyROOT.py”, line 158, in main
myThread = TThread(“myThread”,filler_function)
TypeError: none of the 5 overloaded methods succeeded. Full details:
TThread::TThread(long id = 0) =>
takes at most 1 arguments (2 given)
TThread::TThread(void*()(void) fn, void* arg = 0, TThread::EPriority pri = kNormalPriority) =>
could not convert argument 1
TThread::TThread(void()(void) fn, void* arg = 0, TThread::EPriority pri = kNormalPriority) =>
could not convert argument 1
TThread::TThread(const char* thname, void*()(void) fn, void* arg = 0, TThread::EPriority pri = kNormalPriority) =>
could not convert argument 2
TThread::TThread(const char* thname, void()(void) fn, void* arg = 0, TThread::EPriority pri = kNormalPriority) =>
could not convert argument 2

I’m not sure I understand why.
Cheers,

  • Mauro.

The second argument of TThread expects a C-like function, but gets a Python function. No idea how to convert the python function to C-like function.

Ask better here:
viewforum.php?f=14

Hi,

I think you should reconsider the ingredients of your meal :slight_smile: E.g. I don’t understand why you want to use TThread here instead of a Python equivalent (which must exist, right?)

Alternatively, if you want to use TThread it might be better to use a C++ function for it to run.

We have some interfaces where we can accept python functions (e.g. fitting), but in general passing python functions to a C++ function that expects a function pointer is courageous.

Cheers, Axel.

Hi Axel,
thanks for the reply.
I’m not an expert in programming. I just wanted to develop my program in python and I naively wanted to use TThread within my python program.

I’m not sure I understand how can I use C++ with python.
By the way, is there a way to overcome the problem within Python ?

Many thanks,

  • Mauro.

Hi,

I see you opened Problem using TThread with PyROOT to discuss the “threaded python” issue further.

I don’t know what to say - you are adding lots of complexity to your problem (combining python and C++; and much worse: with threading!) and then asking for a simple solution…

If you indeed want to use the GUI I can warmly recommend you to stay on the C++ side.

Cheers, Axel.