Hi! I've run into an issue where I get the following error:

```
"{binary_path} appears to have been moved or deleted since this application 
was launched. Continouation from this state is impossible. Exiting now."
```

Context:
- The application starts at a scheduled time;
- Upon an external event, the application starts a background process using 
the `multiprocessing` library
- In between the two, a deploy can alter the symlink to the binary by 
removing or updating it
- If the deploy has happened, the background process cannot start and dies 
with the error from above

>From what I've read, the error is triggered when the background process 
tries to import python modules which it cannot find.
What I'm trying to understand is why that happens if the background process 
is started using the `fork` method? And then, as a follow-up, is there 
anything that can be done to mitigate this? 

The parent process works fine even though the binary has been altered. I 
suppose it is running off an temp directory? Could the background process 
also be started using it?

Code to reproduce:
```
import multiprocessing as mp
import sys, time, platform, pathlib
import faulthandler

EXE = pathlib.Path(sys.executable) # PyInstaller onefile
HB = pathlib.Path.cwd() / "heartbeat.log"
LOG = pathlib.Path.cwd() / "test.log"

def log(msg):
LOG.write_text((LOG.read_text() if LOG.exists() else "") + msg + "\n")

def worker():
log("worker: start")
for _ in range(20):
HB.write_text((HB.read_text() if HB.exists() else "") + msg + "\n")
time.sleep(0.5)
log("worker: done")

def try_delete_target(path: pathlib.Path):
try:
path.unlink()
log(f"deleter: successfully unlinked {path}")
except Exception as e:
log(f"deleter: failed to unlink {path}: {type(e).__name__}: {e}")

def spawn_worker(func):
mp.freeze_support()
log(f"parent: {mp.get_start_method()}")
p = mp.Process(target=func)
p.start()
return p

def main():
faulthandler.enable(open("faulthandler.txt", "w"))
LOG.write_text("")
HB.write_text("")
log(f"parent: exe path = {EXE}")
log(f"parent: platform = {platform.platform()}")

try_delete_target(EXE)
spawn_worker(worker)
log("parent: spawned background worker")

for i in range(6):
log(f"parent: tick {i}")
time.sleep(1)
log("parent: exiting")


if __name__ == "__main__":
main()
```

The platform I'm running this on is Linux. Would really appreciate some 
help and intuition on this one, thanks! :) 

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/pyinstaller/75e7b422-3ffa-4af4-87fd-21a5773a0f3fn%40googlegroups.com.

Reply via email to