-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run crashes on Linux if run outside of main thread #70
Comments
Thanks Alex, I can confirm that I can run the test ok on windows, but I get a seg fault on linux (specifically through using the Windows Subsystem for Linux). |
some debugging: running in
for standard layers:
|
it seems that there are various issues around the GIL when it comes to calling Python from inside C threads? |
Irrespective of this issue, I will recommend using a Process instead of a python thread as the latter will affect the responsiveness of the GUI. The main problem with the python process is that it uses pickling to copy inputs i.e. Project and Controls but because of some issue the Project class cannot be pickled (Apologies, for some reason we did not open an issue on GitHub). We could either try to fix the pickling issue so we can use the
or we could just pickle the inputs to RATMain
|
@StephenNneji in the GUI code i was using a |
As far as I know, QThread are just a wrapper on the python thread https://stackoverflow.com/questions/1595649/threading-in-a-pyqt-application-use-qt-threads-or-python-threads except if something has been changed in PyQt6 |
yeah, with the main benefits of the wrapper being that it handles signals/slots and so on to avoid the thread choking up the GUI! as in the post:
will try it with a ProcessPoolExecutor when we can get the thing pickled correctly anyway and see if it's more performant |
Memory checking shows an
Specifically, the line |
We also find a memory issue in |
fascinatingly, it works completely fine if RAT is imported inside the thread: from concurrent.futures import ThreadPoolExecutor
def thread_func():
import RATapi as RAT
project, results = RAT.examples.DSPC_standard_layers()
return project, results
executor = ThreadPoolExecutor()
future = executor.submit(thread_func)
project, results = future.result() doesn't segfault. even stranger is that if you import it outside the thread and then again inside it does segfault, but i may just be missing some detail of python import implementation here: from concurrent.futures import ThreadPoolExecutor
import RATapi as RAT
def thread_func():
import RATapi as THREADRAT
project, results = THREADRAT.examples.DSPC_standard_layers()
return project, results
executor = ThreadPoolExecutor()
future = executor.submit(thread_func)
project, results = future.result() |
I've had a fresh look at @arwelHughes Can you please confirm whether the code on line 35 should instead read: |
Hi Paul,
Well, firstly I have a different version to you – did you put the ‘disp’ in for debugging?
***@***.***
It probably should be ‘thisContrastLayers(I,:)…. as you suggest, but in practice it makes no difference. That line is never actually reached in normal usage (because there will never be an empty layer), but I think it was necessary because otherwise Coder throws a ‘thisContrastLayers is not fully defined on all execution paths’ error (I think!).
Cheers,
Arwel
From: Paul Sharp ***@***.***>
Date: Monday, 2 September 2024 at 17:31
To: RascalSoftware/python-RAT ***@***.***>
Cc: Hughes, Arwel (STFC,RAL,ISIS) ***@***.***>, Mention ***@***.***>
Subject: Re: [RascalSoftware/python-RAT] run crashes on Linux if run outside of main thread (Issue #70)
I've had a fresh look at allocateLayersForContrast.m in the MATLAB source:
image.png (view on web)<https://github.com/user-attachments/assets/31d9b618-85a5-4d22-8caf-c6688f8b3dee>
@arwelHughes<https://github.com/arwelHughes> Can you please confirm whether the code on line 35 should instead read: thisContrastLayers(i, :) = [];. I can't guarantee this bug is causing the memory issues, but we should look to fix it urgently regardless.
—
Reply to this email directly, view it on GitHub<#70 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AGMNVXUMIHUG5SAJXSNJDM3ZUSHEZAVCNFSM6AAAAABM4FBUK2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMRVGA3TIOJZHE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Thanks Arwel. Yes, the disp lines are for debugging. |
since we've merged #74 i've found that RATMain does not produce a segfault in a separate process (only a separate thread). so this issue is a lot less urgent since we can use processes for multiprocessing in the GUI! |
closed by #78 |
On Linux (including IDAaaS), attempting to run the following script will produce a segfault:
This is an issue because RasCAL-2 needs long-running code (e.g.
RAT.run()
) to run outside the main loop, as the main loop is used for handling and updating the GUI itself. It seems to run successfully on Windows (@DrPaulSharp managed to run it okay). If anyone else would like to run the script on whatever devices they have to hand that'd be useful!Various observations:
standard_layers
orcustom_XY
examples but NOT thecustom_layers
examples which run successfully.DSPC_standard_layers
it happens no matter what procedure is chosen.calculate
procedure, theRunning [procedure]
message is produced before it segfaults.The text was updated successfully, but these errors were encountered: