rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

My pp generated app doubles itself and it's children when run - why? #43

Closed PesoMemo closed 2 years ago

PesoMemo commented 3 years ago

I created a Tk GUI app using AS Perl v5.20.2 with pp.pm v 0.992 on Windows 10 .

The GUI does a Win32::Process::Create to basically fork off a task to do URL fetches asynchronously (so as not to lock up the GUI part). After building with pp, everything runs ok (w or w/o --gui switch), but I get 2 copies of the GUI and 2 copies of the forked off async app showing up in Task Manager. When I kill the forked off async task from the GUI task and exit the GUI task, both of the GUI processes exit OK, but only one of the async processes gets killed. This leaves me with multiple async tasks floating around - one per run. 1) Why are the processes doubled? 2) Why does the second async task not die?

rschupp commented 3 years ago

Are you sure that you really see 2 copies of the GUI process? This is how a pp packed executable foo.exe works on Windows:

What is the actual call to Win32::Process::Create?

PesoMemo commented 3 years ago

Win32::Process::Create($PObj, $pcExe, $pcCmd, 0, NORMAL_PRIORITY_CLASS, '.') or do { ... };

where: $pcExe = 'D:/tmp/Pub/GetFileUI.exe' $pcCmd = 'GetFileUI D:/tmp/Pub'

The GUI processes are 728K and 36,220K in size. The async processes are 740K and 20,304K

Exiting the GUI kills the async process with $PObj->Kill(15) and the smaller of the two goes away in Task Manager - the big one remains.

I wasn't aware of the cache dir before - I found it in D:/Temp.

rschupp commented 3 years ago

$pcExe = 'D:/tmp/Pub/GetFileUI.exe'

I guess this is another pp-packed executable? This would explain what you're seeing - instead of killing the "real" async process you're killing its "boot" process (note that the "boot" process doesn't handle any signals, esp. it will not kill its child).

Why not use fork instead of Win32::Process::Create? Or look into the --reusable option of pp?

PesoMemo commented 3 years ago

Yes, they're both pp generated. I'll look into those two options and get back to you.

I did some reading and don't follow how a fork/exec is really any different than using Create (and Windoze has to simulate fork in the same process). I looked at the 5 lines of experimental --reusable documentation and totally don't understand how it works at all - let alone for my app. :)

So before I try a whole bunch of bound to fail options, how does the --reusable work with my two tasks ? I need two totally separate processes to keep it async. Maybe an example?