[Ironpython-users] ipy.exe hangs after closing IronPython WFP application

Jackie Sproat JackieSproat at smarttech.com
Thu Jan 3 20:24:01 CET 2013


Here is the IronPython code I use to start and stop my app:
Perhaps the ShutdownMode has something to do with ipy.exe hanging (which seems to suggest app is not shutting down properly!)?

def Run_App_Threaded():
        global evt
        evt = AutoResetEvent(False)
        print "initializing..."
        thrd = Thread(ThreadStart(thread_start))
        thrd.ApartmentState = ApartmentState.STA
        thrd.IsBackground = True
        thrd.Start()

        evt.WaitOne()
        clr.SetCommandDispatcher(DispatchConsoleCommand)

def thread_start():
    try:
        global app
        app = Application()
        global mywin
        mywin = WpfApp1()
        mywin.Show()
        app.Startup += on_startup
        #app.ShutdownMode = ShutdownMode.OnExplicitShutdown
        app.ShutdownMode = ShutdownMode.OnMainWindowClose
        app.Run()
    finally:
        clr.SetCommandDispatcher(None)
        print "finally"
        itLives = Thread.CurrentThread.IsAlive
     print itLives
     print "hi"
     #if itLives:
     Thread.CurrentThread.Abort()
     print "Abort"
     #app.Exit(0) #exception: BoundEvent is not callable
     #app.Shutdown(0)
     #System.Environment.Exit(0) #this is the easy way to prevent it from hanging but, I want to do it RIGHT;)

def on_startup(*args):
     print "on_startup"
     global dispatcher
     dispatcher = Dispatcher.FromThread(Thread.CurrentThread)
     evt.Set()

def Close_App():
    #not on background thread, so we need to call Invoke
    print "invoking dispatcher"
    dispatcher.Invoke(Close_App_Delegate)

def Close_App_Delegate():
    mywin.Close_Window()
    app.Exit
    app.Shutdown()


>> Here is the output:
Finally
True
hi

>>Conclusion:
CurrentThread is Alive, but Abort doesn't work; ipy.exe  hangs with or without this call to Abort()???
Why isn't ipy.exe not exiting?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20130103/c7637d28/attachment.html>


More information about the Ironpython-users mailing list