Multithread DLL fails

Hi All,

I'm trying to run dll functions from multithreaded GUI in wxpython.
When i try to run those functions from the 'Worker Thread' i get runtime error "abnornal program termination".

If i try to run the dll functions in the main loop thread, it works fine (but then the mainloop is blocked...)

the code looks something like this (worker thread is taken from wxpyhton book):

import xxx (xxx is the dll)

class WorkerThread(threading.Thread):
    """
    This just simulates some long-running task that periodically sends
    a message to the GUI thread.
    """
    def __init__(self, threadNum, window, num_of_tests, ver, platform, savetodb, genfile, lock):
        threading.Thread.__init__(self)
        self.threadNum = threadNum
        self.window = window
        etc...

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="xxxxx", pos=(10,10), size=(850,710))
        wx.InitAllImageHandlers()
        self.CreateMenuBar()
        self.AddToolBar()
        self.AddStatusBar()

app = wx.PySimpleApp(redirect=False)
frame = TestFrame()
frame.Show()
app.MainLoop()

so, when calling function from within the TestFrame it's ok. When trying to run from the worker thread it fails.

Any suggestions ??

Thanks in advance,
Roy.

···

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

ROY ZINN <royzinn <at> hotmail.com> writes:

    def __init__(self, threadNum, window, num_of_tests, ver, platform,
savetodb, genfile, lock):
        threading.Thread.__init__(self)
        self.threadNum = threadNum
        self.window = window
        etc...

Hi,

I hope your etc... has:
def run(self):
      # do whatever dll stuff you are doing
      wx.CallAfter(window.Method, argument) # return control to wx

Also, make sure you call thread.start() after you create an instance of your
thread class otherwise nothing will be done. I remember I once forget to do that.

ROY ZINN wrote:

Hi All,

I'm trying to run dll functions from multithreaded GUI in wxpython.
When i try to run those functions from the 'Worker Thread' i get runtime error "abnornal program termination".

If i try to run the dll functions in the main loop thread, it works fine (but then the mainloop is blocked...)

What is going on inside the dll function? Does it interact in any way with the main thread? With the GUI? Does it acquire/release the Python global interpreter lock?

···

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

Hi Robin,

The DLL functions are functions that control some Agilent device (controlled through GPIB) that we wrapped with python.

I'm not acquiring / releasing the Python global interpreter lock.

within the worer thread i'm trying to call a function such as Agilent.reset() that does nothing but sending the "*rst" on the GPIB.

the thing is, if i call the function from the TestFrame it works fine.

The dll was compiled with multithread support.

Thanks again,
Roy

···

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

ROY ZINN wrote:

Hi Robin,

The DLL functions are functions that control some Agilent device (controlled through GPIB) that we wrapped with python.

I'm not acquiring / releasing the Python global interpreter lock.

within the worer thread i'm trying to call a function such as Agilent.reset() that does nothing but sending the "*rst" on the GPIB.

the thing is, if i call the function from the TestFrame it works fine.

The dll was compiled with multithread support.

The only thing I can suggest at this point is to run it in the debugger and trace through the DLL code to see what it is trying to do that fails.

···

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