# Crash calling gClient.GetRoot() with PyROOT

**URL:** <https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301>\
**Category:** ROOT\
**Created:** [December 3, 2016, 1:08pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301 "2016-12-03T13:08:05Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 3, 2016, 1:08pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/1 "2016-12-03T13:08:05Z")

</div>

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.

- Mauro.  
[TestPyROOT.py](https://root-forum.cern.ch/uploads/default/original/2X/b/bdb333b297f5bb639a191d320625343bec0bc3b5.py) (3.66 KB)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 4, 2016, 8:09am UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/2 "2016-12-04T08:09:24Z")

</div>

Hi Mauro,

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

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 4, 2016, 11:30am UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/3 "2016-12-04T11:30:01Z")

</div>

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](http://TestPyROOT.py) -i in -o out

Many thanks,

- Mauro.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [December 4, 2016, 7:32pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/4 "2016-12-04T19:32:52Z")

</div>

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:

```auto
gClient.GetRoot()
```

with

```auto
ROOT.TGClient.Instance().GetRoot()
```

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 4, 2016, 9:44pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/5 "2016-12-04T21:44:33Z")

</div>

Many thanks.  
that works nicely.

Ciao,

- Mauro.

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 4, 2016, 10:48pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/6 "2016-12-04T22:48:49Z")

</div>

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.

- Mauro.  
[TestPyROOT.py](https://root-forum.cern.ch/uploads/default/original/2X/0/0164fde6f08e4826292d762cc6fb2d44cf46ab46.py) (4.88 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [December 5, 2016, 8:14am UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/7 "2016-12-05T08:14:22Z")

</div>

You need a TThread. Take a look at:

> [@Monitor a histogram while running](https://root-forum.cern.ch/t/monitor-a-histogram-while-running/22287/1):
>
> Dear Experts, Is there a way to monitor a histogram while running a script? For example, while I run the following code in a terminal, { TH1D \* h = new TH1D("h", "h", 10, 0, 10); for ( int i = 0; i \< 1000000; i++ ) { sleep(5); h-\>Fill(2); } } Can I draw “h” from another terminal? I can definitely write it to a file, but it will generate 1000000 histograms, which I don’t want. Is there an elegant way to know the content of a histogram w…

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 7, 2016, 2:16pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/8 "2016-12-07T14:16:46Z")

</div>

Hi again ☹  
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,

- Mauro.  
[TestPyROOT.py](https://root-forum.cern.ch/uploads/default/original/2X/0/086da3b39b2d5e9c8d5a9651fca8c48e2ddc2505.py) (5.02 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [December 7, 2016, 4:09pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/9 "2016-12-07T16:09:05Z")

</div>

Why do you want to thread the init function?

I think you rather thread the “iteration function”

```auto
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.

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 7, 2016, 4:27pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/10 "2016-12-07T16:27:54Z")

</div>

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](http://TestPyROOT.py)”, line 191, in   
sys.exit(main())  
File “[TestPyROOT.py](http://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.

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [December 7, 2016, 4:37pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/11 "2016-12-07T16:37:03Z")

</div>

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](https://root.cern.ch/phpBB3/viewforum.php?f=14)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [December 7, 2016, 4:41pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/12 "2016-12-07T16:41:23Z")

</div>

Hi,

I think you should reconsider the ingredients of your meal 🙂 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.

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [December 7, 2016, 4:46pm UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/13 "2016-12-07T16:46:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [December 8, 2016, 8:11am UTC](https://root-forum.cern.ch/t/crash-calling-gclient-getroot-with-pyroot/22301/14 "2016-12-08T08:11:17Z")

</div>

Hi,

I see you opened [Problem using TThread with PyROOT](https://root-forum.cern.ch/t/problem-using-tthread-with-pyroot/22331/1) 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.
