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
{{ message }}
Repository navigation
Occasional python crash in multiprocessing\forking.py on Windows. #718
With the latest version of Emscripten from the incoming branch, I get this crash maybe one out of three times when compiling with emcc:
Exception WindowsError: WindowsError(5, 'Access is denied') in <Finalize object, dead> ignored
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\tools\Python26\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\tools\Python26\lib\multiprocessing\util.py", line 277, in _exit_function
p._popen.terminate()
File "C:\tools\Python26\lib\multiprocessing\forking.py", line 274, in terminate
_subprocess.TerminateProcess(int(self._handle), TERMINATE)
WindowsError: [Error 5] Access is denied
Error in sys.exitfunc:
Traceback (most recent call last):
File "C:\tools\Python26\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "C:\tools\Python26\lib\multiprocessing\util.py", line 277, in _exit_function
p._popen.terminate()
File "C:\tools\Python26\lib\multiprocessing\forking.py", line 274, in terminate
_subprocess.TerminateProcess(int(self._handle), TERMINATE)
WindowsError: [Error 5] Access is denied
No, that's an error message I haven't seen on the bot output. It runs on Windows Vista. I do Windows builds on a Windows 7, on the current stable branch, and haven't gotten this issue either.
Are there some options to control how emscripten behaves with multithreading?
Interestingly, if buildbot invokes the build, this crash does not happen (!!!) It is perhaps exactly due to that buildbot does not spawn a visible shell window, and the bug is exactly related to behavior with shell windows.
Well well.. just random trial-and-effort mucking around sometimes does help. I managed to work around the problem (and now incoming builds successfully) by redirecting stdin in the vs-tool wrapper exes. See the commit that added the workaround: juj/vs-tool@0cbf44d
Are you using the vs-tool wrappers @SiggyBar? If not and you have another external build tool invoke emscripten, it can exhibit the same problem. Perhaps try if going through vs-tool helps, if it's possible in your setup?
(This is assuming that as indicated by my previous googling that our issues are caused by the same root problem)
(Btw, we occasionally got that scons crash that this post talks about, and the patch fixed it.)
Regarding the verification of the source issue, I don't understand how I can verify that we are indeed talking about the same problem unless I can make a fix that works with scons.
The emscripten wrappers in vs-tool repository don't have anything to do with Visual Studio itself. You do not need Visual Studio to use them. They are just .exe files to allow calling 'emcc.exe' on the command line instead of having to call 'python emcc', which cmake and Visual Studio neither can easily understand.
On a side note I noticed that your vs-tool implements response file parsing. I had to do the same thing to get emscripten to work with scons on Windows. Maybe it would be better if emcc would do the response file parsing itself?
Here is the command line I use to call emcc (em++) from scons:
importshleximportsubprocessimportsysdef_ParseWithResponseFile(args):
''' Parses the given list of arguments and (recursively) replaces all args that are filenames with a leading '@' sign with their content. '''newArgs= []
forarginargs:
ifarg[0] =='@':
try:
withopen(arg[1:]) asfile:
forlineinfile.readlines():
# Setting posix to True gives wrong paths, but with# it set to False we need to unquote ourselves...tokens=shlex.split(line, comments=True, posix=False)
tokens= [t[1:-1] ift[0] =='"'andt[-1] =='"'elsetfortintokens]
newArgs+=_ParseWithResponseFile(tokens)
exceptIOError:
# If we could not open the file, we simply add the# argument unchanged.newArgs.append(arg)
else:
newArgs.append(arg)
returnnewArgsif__name__=='__main__':
exit(subprocess.call(_ParseWithResponseFile(sys.argv[1:])))
The call stack error might be due to the llvm switch issue we are investigating in the other bug. Other testcases would be useful (as usual, the files from EMCC_DEBUG).
Yeah, I now know that this call stack error was caused exactly by that long GLenum->string switch-case function, so no need to go into that further here. It did not however resolve this problem with multiprocessing "access is denied", which is the next one to be solved.
If I brutishly go into File "c:\python27\lib\multiprocessing\pool.py", line 476, in _terminate_pool
and replace the line
p.terminate()
with
try:
p.terminate()
except WindowsError:
pass
I get past the error, and the Emscripten builds succeed fine, and I get proper runnable .html files. The issue seems to be somehow caused by when Python tries to tear down the multiprocessing worker pool at process exit time. I don't know how big of a hack this is at the moment.
That's good enough for me, I don't know any more about the details of what's going on, but since emscripten is building fine, I'm happy with this. Cross-checking with the stack provided by @SiggyBar in first post, the call stacks for us seem to be a bit different. But might this patch help in your case still?
This should have been fixed some time ago, and also another call site with the same kind of issue should also be fixed (#4404), so we should no longer be seeing Access is Denied errors on Windows (when tearing down multiprocessing pools).
You mean an MSI installer for emsdk? I don't remember emsdk ever having such a thing but it could just be before my time (in which case we stopping a long time ago). Or perhaps there was an MSI build that was maintained outside the core project?
If you like windows installers maybe you will like recent chocolaty package that was recently added.
Activity
SigmundVik commentedon Nov 18, 2012
I should mention that this happens when I compile my own code, I have not seen it while running tests.
kripken commentedon Nov 20, 2012
@juj , have you seen something like this on the test bots?
juj commentedon Nov 21, 2012
No, that's an error message I haven't seen on the bot output. It runs on Windows Vista. I do Windows builds on a Windows 7, on the current stable branch, and haven't gotten this issue either.
Are there some options to control how emscripten behaves with multithreading?
juj commentedon Nov 23, 2012
Sigh.. this seems to be the same old "Handle is Invalid" problem in disguise.
Don't yet know for a workaround for this case.
juj commentedon Nov 23, 2012
Well well.. just random trial-and-effort mucking around sometimes does help. I managed to work around the problem (and now incoming builds successfully) by redirecting stdin in the vs-tool wrapper exes. See the commit that added the workaround: juj/vs-tool@0cbf44d
Are you using the vs-tool wrappers @SiggyBar? If not and you have another external build tool invoke emscripten, it can exhibit the same problem. Perhaps try if going through vs-tool helps, if it's possible in your setup?
(This is assuming that as indicated by my previous googling that our issues are caused by the same root problem)
SigmundVik commentedon Nov 27, 2012
Thank you for your feedback, @juj. I am not using the vs-tool wrappers, I invoke
em++from scons.I see that there already is a fix for http://bugs.python.org/issue3905 in tools\shared.py, is it not possible to add the redirection fix from juj/vs-tool@0cbf44d there?
juj commentedon Nov 27, 2012
This fix juj/vs-tool@0cbf44d does not "complete" or "improve" on top of this fix https://github.com/kripken/emscripten/blob/master/tools/shared.py#L8 . They aim to do the exact same thing. The problem with the bug in this issue you reported, as it seems, is that it occurs from a different codepath what this fix https://github.com/kripken/emscripten/blob/master/tools/shared.py#L8 has access to. The codepath goes somewhere inside the multiprocessing library in python, and therefore there is no straightforward way to apply https://github.com/kripken/emscripten/blob/master/tools/shared.py#L8 to it. In my case, I noticed that using juj/vs-tool@0cbf44d avoids the issue also in multiprocessing, and hopefully throughout the whole emscripten process. It might actually make https://github.com/kripken/emscripten/blob/master/tools/shared.py#L8 obsolete, but only if emscripten is run via juj/vs-tool exe wrappers.
So, in short, I don't know how to get "inside" python multiprocessing lib in any other way except via the method I used in juj/vs-tool.
Did that clear or confuse even more? o_O
If you have the time, try testing whether juj/vs-tool wrappers even help avoid the problem in your case, to confirm 100% if we are talking about the same source issue, since our error messages did differ a bit (Handle is Invalid vs Access is Denied). Installation instructions for that are here: https://github.com/kripken/emscripten/wiki/Using-Emscripten-from-Visual-Studio-2010
SigmundVik commentedon Nov 28, 2012
Maybe we can patch the python multiprocessing lib in a similar way to how
spawnve()was patched for Windows here:http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2956316
(Btw, we occasionally got that scons crash that this post talks about, and the patch fixed it.)
Regarding the verification of the source issue, I don't understand how I can verify that we are indeed talking about the same problem unless I can make a fix that works with scons.
juj commentedon Nov 28, 2012
The emscripten wrappers in vs-tool repository don't have anything to do with Visual Studio itself. You do not need Visual Studio to use them. They are just .exe files to allow calling 'emcc.exe' on the command line instead of having to call 'python emcc', which cmake and Visual Studio neither can easily understand.
SigmundVik commentedon Nov 28, 2012
Thanks, now I get it :)
On a side note I noticed that your vs-tool implements response file parsing. I had to do the same thing to get emscripten to work with scons on Windows. Maybe it would be better if emcc would do the response file parsing itself?
Here is the command line I use to call emcc (em++) from scons:
with cmdFwd.py implemented like this:
juj commentedon Jan 13, 2013
I am now seeing this same bug on my newly installed Win8 computer. Don't yet know how to resolve.
juj commentedon Jan 13, 2013
So far I've only seen this in release mode builds, never in debug, and it seems to occur systematically on release builds.
On another note, the error
seems to be related to something completely different.
kripken commentedon Jan 13, 2013
The call stack error might be due to the llvm switch issue we are investigating in the other bug. Other testcases would be useful (as usual, the files from EMCC_DEBUG).
juj commentedon Jan 13, 2013
Yeah, I now know that this call stack error was caused exactly by that long GLenum->string switch-case function, so no need to go into that further here. It did not however resolve this problem with multiprocessing "access is denied", which is the next one to be solved.
juj commentedon Jan 14, 2013
If I brutishly go into File "c:\python27\lib\multiprocessing\pool.py", line 476, in _terminate_pool
and replace the line
with
I get past the error, and the Emscripten builds succeed fine, and I get proper runnable .html files. The issue seems to be somehow caused by when Python tries to tear down the multiprocessing worker pool at process exit time. I don't know how big of a hack this is at the moment.
juj commentedon Jan 14, 2013
This one lists a very similar looking issue: http://stackoverflow.com/questions/5573257/windowserror-error-5-access-is-denied-when-trying-to-kill-a-subprocess-pytho
Apparently 'Access is denied' can be caused if the process that is .terminate()d has already exited.
juj commentedon Jan 14, 2013
I settled to patching Python27\lib\multiprocessing\pool.py locally with the following:
That's good enough for me, I don't know any more about the details of what's going on, but since emscripten is building fine, I'm happy with this. Cross-checking with the stack provided by @SiggyBar in first post, the call stacks for us seem to be a bit different. But might this patch help in your case still?
kripken commentedon Jan 15, 2013
Separately from confirming its the same issue for @SiggyBar, it looks like we should push that terminate except patch.
juj commentedon Jan 15, 2013
The Windows build bot (which was switched to run on Windows 8 Pro 64-bit) now also runs the patched code, and it does report several of these errors during the run: http://clb.demon.fi:8112/builders/win-emcc-incoming-tests/builds/169/steps/Test%20emscripten%20incoming/logs/stdio
My Windows 7 laptop does not give these exceptions.
juj commentedon Jun 29, 2016
This should have been fixed some time ago, and also another call site with the same kind of issue should also be fixed (#4404), so we should no longer be seeing Access is Denied errors on Windows (when tearing down multiprocessing pools).
pemryan commentedon Sep 22, 2020
still happening occasionally on Python 3.8.5 @ Windows10
jeffRTC commentedon Jan 15, 2021
@juj I hit this problem on Python 3.9
Since you guys removed msi installer, I had to restore manual jargon :((
sbc100 commentedon Jan 15, 2021
You mean an MSI installer for emsdk? I don't remember emsdk ever having such a thing but it could just be before my time (in which case we stopping a long time ago). Or perhaps there was an MSI build that was maintained outside the core project?
If you like windows installers maybe you will like recent chocolaty package that was recently added.
kripken commentedon Jan 15, 2021
I think @juj maintained an MSI installer many years ago, but I'm not aware of anyone supporting one currently.
Chocolatey as mentioned is an option, and also the normal download instructions.
jeffRTC commentedon Jan 15, 2021
@sbc100 @kripken MSI installer was on your Docs on 2020
It had green logo on left side when launched.
jeffRTC commentedon Jan 15, 2021
I'm 99% sure I didn't time travel
kripken commentedon Jan 15, 2021
It's possible the docs were outdated, sorry about that. They look accurate now at least.