[Paraview] python plugin custom dialog causes paraview to hang

pat marion pat.marion at kitware.com
Sun Oct 17 16:09:49 EDT 2010


Before compiling paraview on windows, you might try this-

You can prevent processEvents from being called by taking the python console
widget out of the loop.  Paraview sets sys.stdout and sys.stderr to a helper
object that directs the output to the widget (where processEvents is
called):

 >>> import sys

>>> sys.stdout.__class__

<type 'vtkPVPythonInterpretorWrapper'>

So you can reroute output to disk:

sys.stdout = open("stdout.txt", "w")
sys.stderr = open("stderr.txt", "w")

Now you won't see any output in the paraview gui, it will be written to
those files instead.  The output isn't flushed on every write, so you might
not see anything in the files until you quit paraview.  You could define
your own stdout object that calls write on a file followed by flush.

Pat

On Sun, Oct 17, 2010 at 3:35 PM, <m.c.wilkins at massey.ac.nz> wrote:

>
> Hi,
>
> > Are you working from a paraview installer, or compiling paraview
> yourself?  I
>
> downloaded stock standard 3.8.1 for Windows.
>
> > was able to reproduce the linux bug (by putting a 'print "hello"' at the
> end)
> > and then solve it by commenting out two lines in ParaView/Qt/Python/
> > pqPythonShell.cxx.  Just search for the lines with "processEvents" and
> comment
> > them out and then recompile.
>
> thanks.  Windows is not my platform of choice, i've never successfully
> compiled up paraview with visual studio before.  anyway now I have a
> lot more motivation, and i do have the Paraview Guide with
> instructions, so I will give it a go.
>
> > I'll try to explain it why this fixes the problem-
> >
> > Before paraview executes the python script it acquires a lock.  The lock
> is
> > part of the python C api to help make things thread safe ( http://
> >
> docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock).
> >   Paraview doesn't use threads, but it uses multiple python interpreters,
> and
> > each interpreter has its own "thread state".  So before any code is
> executed by
> > the paraview python shell, the shell acquires the lock to activate its
> > interpreter.
> >
> > Next, the python script hits a print statement which sends an output
> string to
> > the paraview python shell.  The shell calls processEvents so that the
> widget
> > has an opportunity to repaint itself (make the text appear on your
> screen)
> > without having to wait for the entire python script to complete
> execution.  The
> > problem is that during processEvents, the events generated by calling
> show on a
> > PyQt widget are also processed.  While processing these events, PyQt
> tries to
> > acquire the lock itself, fails, and then waits- paraview hangs because
> this all
> > happens in the same thread.  The fix is either to comment out the
> processEvents
> > call in pqPythonShell.cxx, or release the lock before calling
> processEvents and
> > then reacquire it afterward.
>
> Thanks Pat.  I think I follow.  Although I'm not sure what affect not
> calling processEvents will have on my widget.  Will it never have a
> chance to update?
>
> > I have never tested PyQt+Paraview on Windows, there may be further bugs.
>  Also,
> > there could be other scenarios where the paraview python shell and PyQt
> fight
> > over the lock.
>
> Ok, thanks.
>
> > Hope this helps a bit!
>
> Indeed it does, it is nice to know I'm not trying to figure this out
> all by myself.
>
> Matt
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20101017/bcdf5c51/attachment.htm>


More information about the ParaView mailing list