Tom Bernens Posted April 27, 2017 Share Posted April 27, 2017 I am in need to execute a iron python script asyncronously, without locking up the main application thread. I have a delegate function already defined but any time I try to spawn a new thread, Spotfire simply crashes. Code snippit below. This code works fine when running a standalone application, I can have a parent form still be active and responsive with my IV form also active and responsive, but in spotfire it doesn't seem to want to behave. def SpawnIV(): iv.ShowDialog() CleanupAndSave() iv = ImageViewer(mapping, trellisLevels) t = Thread(ThreadStart(SpawnIV)) t.SetApartmentState(ApartmentState.STA) t.Start(); I have also tried using a worker thread class to invoke the method async, but this simply does nothing: class IVWorker: def __init__(self, imageViewer): self.application = Application self.applicationThread = self.application.GetService[ApplicationThread]() self.iv = imageViewer def Start(self): self.applicationThread.ExecuteOnWorkerThread("IV Worker Thread", self.StartIVWorker) def StartIVWorker(self): self.applicationThread.InvokeAsynchronously(self.SpawnIV) def SpawnIV(): self.iv.ShowDialog() CleanupAndSave() iv = ImageViewer(mapping, trellisLevels) ivWorker = IVWorker(iv) ivWorker.Start() EDIT: I have been able to get this (partly) working using a .NET background worker, however due to the multi threaded scope change, I lose referecenses to all of my imports, is there a way to ensure that when spawning the second thread, all of the imports are carried along with it Normally I would use the sys package however this is not installed in Tibco's implementation of IronPython. Inside of the dialog, any actions result in JIT errors like "range" "len" or "zip" is not defined, which are all functions in the __builtin__ namespace, however it seems like every include is unloaded in the second thread.... def bw_DoWork(sender, args): iv = args.Argument[0] iv.ShowDialog() iv = ImageViewer(mapping, trellisLevels) iv_bw = BackgroundWorker() iv_bw.DoWork += bw_DoWork iv_bw.RunWorkerAsync([iv]) EDIT2: By using the line import __builtin__ at the beginning of every def in my form class, and referencing functions like.. __builtin__.len(), __builtin.range() this problem has been solved Link to comment Share on other sites More sharing options...
Tom Bernens Posted April 28, 2017 Author Share Posted April 28, 2017 EDIT: I have been able to get this (partly) working using a .NET background worker, however due to the multi threaded scope change, I lose referecenses to all of my imports, is there a way to ensure that when spawning the second thread, all of the imports are carried along with it Normally I would use the sys package however this is not installed in Tibco's implementation of IronPython. Inside of the dialog, any actions result in JIT errors like "range" "len" or "zip" is not defined, which are all functions in the __builtin__ namespace, however it seems like every include is unloaded in the second thread.... def bw_DoWork(sender, args): iv = args.Argument[0] iv.ShowDialog() iv = ImageViewer(mapping, trellisLevels) iv_bw = BackgroundWorker() iv_bw.DoWork += bw_DoWork iv_bw.RunWorkerAsync([iv]) EDIT2: By using the line import __builtin__ at the beginning of every def in my form class, and referencing functions like.. __builtin__.len(), __builtin.range() this problem has been solved Link to comment Share on other sites More sharing options...
Nikita Belooussov Posted July 22, 2019 Share Posted July 22, 2019 Hi, I know it has been a while,but I was wondering if you think your code would be able to preform any functions that come with Spotfire. I am guessing it cant since you mentioned that the imported library gets lost. Did you ever solve that issue Thanks Link to comment Share on other sites More sharing options...
Alexandre Verri Posted December 20, 2019 Share Posted December 20, 2019 This is ridiculous, the framework should support background threads out of the box without having to do this annoying approach. Until now, I haven't gotten background threads working, and the lack of documentation and support sucks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now