wxPyTimer

Hello,

I have included a simple program that uses the DISLIN plotting library.
When a wxPyTimer is included for the status bar it crashes after several
resizes of the main window. With the timer left out there is no problem.
This is what I have in use (on Win2000) :
   ActivePython 2.2.1
   wxPython 2.4.0.7
   Numeric 23.0
   DISLIN 8.1

Best regards,

Paul Casteels Paul.Casteels@ua.ac.be Tel: +32.3.8202455
            Fax: +32.3.8202470
University of Antwerp Dpt.Physics
Universiteitsplein 1
B-2610 Wilrijk
Belgium

import sys,time
sys.path.append('c:\\dislin\\python')
import dislin
from wxPython.wx import *
import Numeric

crash = 1

ID_ABOUT=101
ID_EXIT=102
ID_OPEN=103
ID_CLOSE=104

class _win_canvas(wxPanel):
    def __init__(self,parent,ID=-1,pos=wxDefaultPosition,
                 size=wxDefaultSize):
        wxPanel.__init__(self,parent,ID,pos,size)
        self.handle = self.GetHandle()
        self.mode = 'store'
        self.painter = None
        EVT_PAINT(self,self.OnPaint)

    def draw(self,target='xwin'):
        if self.painter:
            dislin.metafl(target)
            if target == 'xwin':
                dislin.x11mod(self.mode)
                dislin.setxid(self.handle,'window')
            pw,ph = self.GetClientSizeTuple()
            spw = pw*6
            sph = ph*6
            dislin.sclmod('full')
            dislin.page(spw,sph)
            self.painter.draw()

    def OnPaint(self,event):
        dc = wxPaintDC(self)
        self.draw()

class plotPainter:
    def __init__(self):
      pass

    def draw(self):
        dislin.scrmod('revers')
        dislin.disini()
        dislin.unit(0)
        pw,ph = dislin.getpag()

  x = Numeric.arange(10.0)
  y = Numeric.array([2.0,6.0,4,3,8,9,11,4,9,3])
        dislin.plot(x,y)
        dislin.endgrf()
        dislin.disfin()
        
class myFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self,NULL,-1,'PyCVT',
                         wxDefaultPosition,wxSize(400,320))
        display = _win_canvas(self)
        display.painter = plotPainter()
        menu = self.MakeMenu()
        self.SetMenuBar(menu)
        self.MakeStatusBar()
        self.filterIndex = 0

        EVT_CLOSE(self,self.OnCloseWindow)

        EVT_MENU(self,ID_OPEN,self.OnMenuOpen)
        EVT_MENU(self,ID_CLOSE,self.OnMenuClose)
        EVT_MENU(self,ID_ABOUT,self.OnMenuAbout)
        EVT_MENU(self,ID_EXIT,self.OnMenuExit)

    def MakeMenu(self):
        fmenu = wxMenu()
        fmenu.Append(ID_OPEN,"&Open","Open a data file")
        fmenu.Append(ID_CLOSE,"&Close","Close the current file")
        fmenu.AppendSeparator()
        fmenu.Append(ID_EXIT,"E&xit","Terminate the program")

        hmenu = wxMenu()
        hmenu.Append(ID_ABOUT,"&About","More information")

        main = wxMenuBar()
        main.Append(fmenu,"&File")
        main.Append(hmenu,"&Help")

        return main

    def MakeStatusBar(self):
        sb = self.CreateStatusBar(2)
        sb.SetStatusWidths([-1,150])
        if crash:
          self.timer = wxPyTimer(self.Notify)
          self.timer.Start(1000)
          self.Notify()

    def Notify(self):
        t = time.localtime(time.time())
        st = time.strftime(" %d-%b-%Y %I:%M:%S",t)
        self.SetStatusText(st,1)

    def OnMenuOpen(self,event):
        dlg = wxFileDialog(self)
        dlg.SetStyle(wxOPEN)
        dlg.ShowModal()
        dlg.Destroy()
    def OnMenuClose(self,event):
        pass
    def OnMenuAbout(self,event):
        dlg = wxMessageDialog(self,"About",wxOK|wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
    def OnMenuExit(self,event):
        self.Close()
    def OnCloseWindow(self,event):
        if crash:
          self.timer.Stop()
          del self.timer
        self.Destroy()

class myApp(wxApp):
    def OnInit(self):
        frame = myFrame()
        frame.Show(TRUE)
        return TRUE
    
app = myApp(0)
app.MainLoop()

Paul Casteels wrote:

Hello,

I have included a simple program that uses the DISLIN plotting library.
When a wxPyTimer is included for the status bar it crashes after several resizes of the main window. With the timer left out there is no problem.
This is what I have in use (on Win2000) :
   ActivePython 2.2.1
   wxPython 2.4.0.7
   Numeric 23.0
   DISLIN 8.1

Can you reproduce the problem without DISLIN?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

No, if I remove the dislin calls from the draw routine it works fine,
only a basic application is left then.
Can you give a hint on how, or if, it's possible to solve this. Should
dislin run in a seperate thread ?

Paul Casteels

···

On Tue, 27 May 2003, Robin Dunn wrote:

Paul Casteels wrote:
> Hello,
>
> I have included a simple program that uses the DISLIN plotting library.
> When a wxPyTimer is included for the status bar it crashes after several
> resizes of the main window. With the timer left out there is no problem.
> This is what I have in use (on Win2000) :
> ActivePython 2.2.1
> wxPython 2.4.0.7
> Numeric 23.0
> DISLIN 8.1
>

Can you reproduce the problem without DISLIN?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Paul Casteels wrote:

No, if I remove the dislin calls from the draw routine it works fine,
only a basic application is left then.
Can you give a hint on how, or if, it's possible to solve this. Should
dislin run in a seperate thread ?

Probably not. Does the crash happen only on resizes? What do the Dislin folks say about it?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Paul Casteels wrote:
> No, if I remove the dislin calls from the draw routine it works fine,
> only a basic application is left then.
> Can you give a hint on how, or if, it's possible to solve this. Should
> dislin run in a seperate thread ?

Probably not. Does the crash happen only on resizes? What do the
Dislin folks say about it?

On resizes what happens is that the cursor keeps the shape of the resize.
The only way to get out (Win2k) is pressing ALT-CTRL-DEL and kill off the
task.
I have also tried to add a PyCrust frame. With the dislin code enabled the
program hangs from the start.

Paul Casteels

···

On Wed, 28 May 2003, Robin Dunn wrote:

> --

Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Paul Casteels wrote:

Paul Casteels wrote:

No, if I remove the dislin calls from the draw routine it works fine,
only a basic application is left then.
Can you give a hint on how, or if, it's possible to solve this. Should
dislin run in a seperate thread ?

Probably not. Does the crash happen only on resizes? What do the Dislin folks say about it?

On resizes what happens is that the cursor keeps the shape of the resize. The only way to get out (Win2k) is pressing ALT-CTRL-DEL and kill off the task.
I have also tried to add a PyCrust frame. With the dislin code enabled the program hangs from the start.

Sounds similar to a deadlock problem with the Python Global Interpreter Lock. Perhaps the DISLIN Python wrappers are not aquiring and releasing the GIL properly and so it has problems with reentrancy into the timer handler or something. I'm not sure what to suggest, other than preventing the resize, or perhaps not using the timer...

···

On Wed, 28 May 2003, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

You are probably right with the GIL. If I run the dislin code in a
separate thread and release a lock from the paint handler it seems to run
fine. Thanks for your the help.

···

On Thu, 29 May 2003, Robin Dunn wrote:

Paul Casteels wrote:
>
> On Wed, 28 May 2003, Robin Dunn wrote:
>
>
>>Paul Casteels wrote:
>>
>>> No, if I remove the dislin calls from the draw routine it works fine,
>>>only a basic application is left then.
>>> Can you give a hint on how, or if, it's possible to solve this. Should
>>>dislin run in a seperate thread ?
>>
>>Probably not. Does the crash happen only on resizes? What do the
>>Dislin folks say about it?
>>
>
> On resizes what happens is that the cursor keeps the shape of the resize.
> The only way to get out (Win2k) is pressing ALT-CTRL-DEL and kill off the
> task.
> I have also tried to add a PyCrust frame. With the dislin code enabled the
> program hangs from the start.
>

Sounds similar to a deadlock problem with the Python Global Interpreter
Lock. Perhaps the DISLIN Python wrappers are not aquiring and releasing
the GIL properly and so it has problems with reentrancy into the timer
handler or something. I'm not sure what to suggest, other than
preventing the resize, or perhaps not using the timer...

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org