[proFit-list] threading and pro fit

Chris Lee laserboy at fusemail.com
Thu Mar 27 04:53:33 CDT 2014


Interestingly enough, I have been experimenting with this, and it appears that, somehow, it all works. Pro fit does open a window for each thread, and all calls to get data from the window seems to end up with the correct data. 

The only two issues are that Pro Fit stops responding for the duration of the script if thread.join() is called before the thread is terminated. And, if a thread terminates due to an unhandled exception, pro fit stalls on the thread.join() call. I guess that could be handled by checking how the thread terminated before calling thread.join() (laziness on my part).

But, whether you intended it to work or not, it seems to handle it all very nicely.

Cheers
Chris

On 27 Mar 2014 (W: 13), at 06:14, proFit Support <profit at quansoft.com> wrote:

> Chris
> 
> These are good questions.
> 
> Even though some parts of pro Fit use multiprocessing, pro Fit as a whole is not thread safe.  Hence, what you are trying to do will not work. In fact, a program like pro Fit has a wealth of global resources (such as data in the data windows, the "current graph", the "current function", the Results window, and so on, which are difficult to share in a threaded environment (there would, e.g. have to be one instance of a current graph per thread, and it remains unclear what should happen when one thread accesses resources used by another thread).
> 
> As a work-around, you can run several pro Fit's at a time, and process part of your files with each of them, and finally join the results and present them in a single pro Fit. To run several pro Fits, you probably best just make copies of the pro Fit application ("pro Fit.app", "pro Fit 1.app", "pro Fit 2.app"). You then start all of them by hand (you need to do so, because the second and further instances will complain that the global preferences file is busy. Then you start a listener Python script on all of the "slave" instances of pro Fit, and a master script on the master instance. The master script e.g. writes tasks as files into a predefined directory, and the slave scripts detect these files and execute the corresponding tasks, also returning their results as files in some global directory. Once the master script has gathered all results, it can process them. Not very elegant, but it should work.
> 
> 
> Hope this helps.
> 
> Best regards
> 
> Kurt Sutter
> QuantumSoft
> 
> 
> On Mar 21, 2014, at 11:42 AM, Chris Lee <laserboy at fusemail.com> wrote:
> 
>> Hi All,
>> 
>> I wonder if anyone has had any experience using threading for python scripts in pro fit?
>> 
>> At present, I have a program that has to process a few hundred files. Each processing operation involves opening a data file, extracting some data from the file, perform several minimizations and closing the file. Each file takes a couple of minutes to process on a single core. 
>> 
>> So, I thought I would thread it. I initiate 4 threads and divide the work up between them. However, it seems to me that pro fit only allows one thread access to data at a time (for instance, only one data window is ever open at a time). And, by calling thread.join(), the entire application becomes unresponsive, so the little window that tells you that a script is running is always in front, no matter what application is currently being used by the user.
>> 
>> Should I, instead of calling thread.join, loop and call thread.isalive, before calling thread.join? or is there some other way to ensure that this works.
>> 
>> Another question: is pf.FrontmostWindow() thread safe? So, if I have two threads, and both open a window, how can I be sure that I get the correct window ID in each thread?
>> 
>> Any advice is welcome :)
>> 
>> Cheers
>> Chris
>> _______________________________________________
>> proFit-list mailing list
>> proFit-list at quantum-soft.com
>> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
> 
> 
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com




More information about the proFit-list mailing list