Czarek.
Czarek.
I tried your suggestions, but it does not work.
These are the lines that spawn process:
process = multiprocessing.Process(name="finderprocess",
target=finderprocess_start, args=(queue,))
process.daemon = True
And the main block:
if __name__ == "__main__" and multiprocessing.current_process().name
== "MainProcess":
multiprocessing.freeze_support()
print "PROCESS NAME: "+multiprocessing.current_process().name
spawn_process()
After compiling, I run and get these messages in the output:
PROCESS NAME: MainProcess
PROCESS NAME: MainProcess
PROCESS NAME: MainProcess
PROCESS NAME: MainProcess
Czarek.
Since Windows does not have a reasonable fork() function, multiprocessing starts
up a new sys.executable process and imports the main module such that it can
locate the other code that it needs to load. I suspect that running a new
sys.executable process is the problem here. Your embedded code is, of course,
always going to run the __main__ block. I suspect that manually written embedded
code is going to do the same thing (pyinstaller does not embed the interpreter
in another C++ program; just repackages it a bit to look nice). There might be
some multiprocessing API that you can call that can determine if you are in a
child process or not. There might be a specific flag in sys.argv that you can
look for.
You may also try having a plain .py file as your main script that just contains
a __main__ block that imports the main function from your Cython extension module.
Or you can stop trying to abuse Cython as a code obfuscator. ;-)
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
Thank you, checking sys.argv worked, there are arguments that help in
distinction between mainprocess and subprocess:
PROCESSNAME: MainProcess
sys.argv: ['cythonembed.exe']
sys.executable: cythonembed.exe
PROCESSNAME: MainProcess
sys.argv: ['cythonembed.exe', '-c', 'from multiprocessing.forking
import main; main()', '--multiprocessing-fork', '1700']
sys.executable: cythonembed.exe
But now I get a win32 unhandled exception :) I'm probably gonna give
up, tried debugging in VS but that is too much for my c++ skills, I
will just go with pyinstaller + cython for compiling obfuscated
sources to pyd, that should be enough.
Here is the win32 unhandled exception info:
"Unhandled exception at 0x1e0a8ce0 (python27.dll) in cythonembed.exe:
0xC0000005: Access violation reading location 0x00000004."
Screenshot of VS debugger's stack trace:
img689. imageshack .us/img689/4486/cythonembedwin32excepti.jpg (remove
the dot)
I am using a global exception handler, overwriting sys.excepthook
(with my errorhandler.excepthook), I've suspected that maybe I do
something wrong in that handler and changed it to only print "asd"
message and os._exit(1), but it didn't help, no message was written to
output, and win32 unhandled exception still remains.
Czarek.
sys.excepthook only handles Python exceptions. You are seeing a segmentation
fault in the C or C++ code.