You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What Platform are you on? (Linux/Windows and which version)
Windows
How to reproduce your issue? Please include a small self contained reproducer. Likely a SConstruct should do for most issues.
This is a race, one of which is rarely seen by me, but had been reported previously by users, it happens when 2 threads from --jobs create the same config cache:
How you invoke scons (The command line you're using "scons --flags some_arguments")
We use --jobs <cpu_count> by default in nuitka
Our workaround is very crude code, but working:
In CacheDir.py:
- if os.path.isdir(path) and len(os.listdir(path)) != 0:
+ # Nuitka: Fix races where there is already the "config".
+ if os.path.isdir(path) and len([f for f in os.listdir(path) if os.p
ath.basename(f) != "config"]) != 0:
Basically it makes config not count, because it could be created right after you were looking for it to not exist. I assume there could still be races, but none have been observed by Nuitka users so far, as far as I know. The fix has been in Nuitka only for a long time. I believe that Windows is more prone to his race, but the issue is definitely there.
given the section of code already has a huge comment about a race condition that it's trying to avoid, we can certainly do more. The comment centers around "exclusive file creation". That's available in Python3 since some version or another, but as long as we have to support Python2 it is not universally available. Maybe a version-conditional bit here would be worth something? (open takes a 'x' mode for files, and os.makedirs takes an exist_ok parameter).
from threading import Lock
....
@contextmanager
def _with_file_Lock():
# This is a singleton, pylint: disable=global-statement
global file_lock
if file_lock is None:
file_lock = Lock()
file_lock.acquire()
yield
if file_lock is not None:
file_lock.release()
def something():
with _with_file_Lock():
if not os.path.isdir(path):
os.makedirs(path)
That is working with every Python version and i not sure how exclusive file creation can solve anything like that.
I have no idea under what conditions the scons code snippet runs - comment talks about processes but that might be inaccurate wording? threading.Lock is fine within a single process but how does it help if there really are multiple processes in play?
@mwichmann I agree that ought to fare even better, but is Python3 only, due to its use of x mode, which is not for Python2. And without x, you would have to be able to tell when the writing of the file is done, or else you risk reading incomplete files.
The easy solution for an application in full control to this issue could be having a EOF indicator on the file content level, so you know if you read was complete or terminated early, then loop on that.
Yes, I'm aware this is a Python3-only answer (see earlier comment); there are some places where we have version-specific blocks and I was just speculating if that would makes sense here. Not my call...
@bdbaddog While Nuitka does 2.6-2.7, 3.3-3.7, I do not need Scons to do that. In fact, right now, there is a gap already for early Python3 versions. But on Windows, there is an easy way to find installed Pythons, and Nuitka has used that method, when Scons didn't do Python3 yet. And now does it for the 3.x versions you don't support.
There are even 2 inline copies, due to Python 2.6 (a patched 2.3.x), after you dropped support for it, only recently did I switch Python 2.7 to the 3.0.4 inline copy. For RHEL they are in the RPM too, I think, and might get used, because you know, RHEL contains no software.
On Debian with packages, I depend on scons from that distribution, and generally on Linux, I am using scons as from the system if it, and often it is installed, or else an inline copy. These are often very old, therefore I have typically workarounds. For instance, the gcc version detection should use --dumpversion which only outputs the version, and there I am monkey patching the gcc tool already to use that, because e.g. CondaCC will give crap there otherwise, and so might some MinGW64, but I forgot about that.
On these systems, issues affect me, but I am e.g. going to keep the temp file workaround with overriding LINKCOM even if 3.0.5 or later will contain a fix, just because it also fixes the bug for systems you are no longer supporting.
You can see many other workaround, e.g. the spawn function is overloaded for Windows, I am not calling del via shell to delete files, I am blacklisting a ton of tools and their detection, as I am not using them, but that sometimes spawns processes and more.
So, long story short, I don't need fixes for the issues from Scons. I just wanted to report them, so they are known to you. And Python 3.5 or higher would be perfectly fine I think, but you make your own decisions.
Any reason you don't run SCons only with supported python versions?
Then whatever other processing you do can be run with whatever other python versions you need.
This would allow you to use newest(er) SCons on all systems.
And/or or you can vendor scons-local distribution into your repo and update/patch as needed.
We at MongoDB have also had occasional situations where it appears that two separate python processes running on different machines race on setting up a new CacheDir on an NFS mount. A python3 only fix would be fine for us.
Activity
mwichmann commentedon Apr 13, 2019
given the section of code already has a huge comment about a race condition that it's trying to avoid, we can certainly do more. The comment centers around "exclusive file creation". That's available in Python3 since some version or another, but as long as we have to support Python2 it is not universally available. Maybe a version-conditional bit here would be worth something? (
opentakes a 'x' mode for files, andos.makedirstakes anexist_okparameter).kayhayen commentedon Apr 13, 2019
In Nuitka I do something like this:
That is working with every Python version and i not sure how exclusive file creation can solve anything like that.
Yours,
Kay
mwichmann commentedon Apr 13, 2019
I have no idea under what conditions the scons code snippet runs - comment talks about processes but that might be inaccurate wording?
threading.Lockis fine within a single process but how does it help if there really are multiple processes in play?mwichmann commentedon Apr 14, 2019
To reply directly to this point, instead of this kind of construct:
instead just try the
makedirsoperation and move on if it fails, then you can do the same with exclusive open on the file:kayhayen commentedon Apr 14, 2019
@mwichmann I agree that ought to fare even better, but is Python3 only, due to its use of
xmode, which is not for Python2. And withoutx, you would have to be able to tell when the writing of the file is done, or else you risk reading incomplete files.The easy solution for an application in full control to this issue could be having a EOF indicator on the file content level, so you know if you read was complete or terminated early, then loop on that.
mwichmann commentedon Apr 14, 2019
Yes, I'm aware this is a Python3-only answer (see earlier comment); there are some places where we have version-specific blocks and I was just speculating if that would makes sense here. Not my call...
bdbaddog commentedon Apr 14, 2019
Sounds like a python3 specific fix would be simpler and better?
@kayhayen - Are you using Py3 or py2 or both? Can you live with running just py3? (if SCons dropped py27 support would it impact you?)
kayhayen commentedon Apr 15, 2019
@bdbaddog While Nuitka does 2.6-2.7, 3.3-3.7, I do not need Scons to do that. In fact, right now, there is a gap already for early Python3 versions. But on Windows, there is an easy way to find installed Pythons, and Nuitka has used that method, when Scons didn't do Python3 yet. And now does it for the 3.x versions you don't support.
There are even 2 inline copies, due to Python 2.6 (a patched 2.3.x), after you dropped support for it, only recently did I switch Python 2.7 to the 3.0.4 inline copy. For RHEL they are in the RPM too, I think, and might get used, because you know, RHEL contains no software.
On Debian with packages, I depend on scons from that distribution, and generally on Linux, I am using scons as from the system if it, and often it is installed, or else an inline copy. These are often very old, therefore I have typically workarounds. For instance, the gcc version detection should use
--dumpversionwhich only outputs the version, and there I am monkey patching thegcctool already to use that, because e.g. CondaCC will give crap there otherwise, and so might some MinGW64, but I forgot about that.On these systems, issues affect me, but I am e.g. going to keep the temp file workaround with overriding
LINKCOMeven if 3.0.5 or later will contain a fix, just because it also fixes the bug for systems you are no longer supporting.https://github.com/Nuitka/Nuitka/blob/412188e3780c054831600f1b9bd7e51ed9384a1b/nuitka/build/SingleExe.scons#L344
You can see many other workaround, e.g. the spawn function is overloaded for Windows, I am not calling
delvia shell to delete files, I am blacklisting a ton of tools and their detection, as I am not using them, but that sometimes spawns processes and more.So, long story short, I don't need fixes for the issues from Scons. I just wanted to report them, so they are known to you. And Python 3.5 or higher would be perfectly fine I think, but you make your own decisions.
Yours,
Kay
bdbaddog commentedon Apr 16, 2019
Any reason you don't run SCons only with supported python versions?
Then whatever other processing you do can be run with whatever other python versions you need.
This would allow you to use newest(er) SCons on all systems.
And/or or you can vendor scons-local distribution into your repo and update/patch as needed.
acmorrow commentedon Apr 16, 2019
We at MongoDB have also had occasional situations where it appears that two separate python processes running on different machines race on setting up a new CacheDir on an NFS mount. A python3 only fix would be fine for us.
mwichmann commentedon Apr 16, 2019
I can push something for this to experiment with... I assume, as it usually is, this fail is not reproducible, just happens "sometimes"?
Avoid cachedir races
Avoid cachedir races
bdbaddog commentedon Dec 29, 2019
Any reproduction of the issue post #3353 being merged?
kayhayen commentedon Dec 29, 2019
No, this is perfect now, closing the issue. Nuitka has been released for months with nothing like it being reported anymore.