Re: Fwd: pyROOT - geometry again

From: <WLavrijsen_at_lbl.gov>
Date: Fri, 28 Mar 2008 15:32:05 -0700 (PDT)


Michal,

> I actually found a dirty workaround for the time being, I will return
> to the thread after solving "hotter issues". I'll have a look at what
> Valeri linked to think of a sure way of getting the right gui.

Valeri is right: it's caused by the 2nd thread. What is going on, is that the opengl window is being fed events from two event loops if it itself is created on the main thread (i.e. from the macro). If it is from the event processing thread (i.e. if you create it via the View menu), it only gets fed from one thread (well, the events are serialized, to be precise). The TGLLogicalShape::Draw() code is not thread safe, hence the problem if two Draw() calls cross/overlap.

The best solution that I can think of (assuming that you have no need for the python prompt next to the graphics window), is to write your own event loop on the main thread, and switch off the other one. That way, you also do not need to run python in interactive mode.

That is, at the top of your script:

   import ROOT
   ROOT.PyConfig.StartGuiThread = 0

and at the end of the main program:

   import time
   while 1:

      try:
         time.sleep( 0.1 )
         ROOT.gSystem.ProcessEvents()
      except Exception:
         pass

and run with:

   $ python myscript.py

And it should work from there ...

If you do need both the prompt and the window, you can startup the GUI on its own thread and have the ProcessEvents() call on that same one. (I.e. all in one BuildGUI() function that has the above loop as its final code, started from a thread.)

Best regards,

           Wim

-- 
Wim.Lavrijsen_at_cern.ch   --   WLavrijsen_at_lbl.gov   --   www.lavrijsen.net

"Your day will be somewhat dictated by authority."      --fortune cookie
Received on Fri Mar 28 2008 - 23:31:58 CET

This archive was generated by hypermail 2.2.0 : Mon Mar 31 2008 - 17:50:01 CEST