0

I made a python exe that runs in the background for database importing and exporting. The exe runs via a php script. Here's the general flow:

  1. User visits the exporting page and clicks the export button.
  2. PHP throws an ajax that runs the exporting exe
  3. The exporting exe creates a file containing the exported data and writes 100 on a result.txt file
  4. PHP checks the result.txt file to see if the result is 100 or not. If it is, then PHP throws an ajax killing the exporting exe

It's not the most ground-breaking process, yes. However, the process works. I tried multiple tests and I got a "working" result of 16/20. The 4 times the exe failed was when I edited my config with the wrong user, password, database name, or host.

When the program fails, it doesn't end itself. It keeps running while the php script waits for its response. I tried adding the exit() statement in all of my error handlers but it doesn't seem to work. So, what I did next was to test the pyw script of that program. I added a print(1) statement inside the error handlers to see if the pyw script passes through them and it does. Check this picture here

So, I did another thing. This time I coded the script to edit the contents of the result.txt file to "xxx" if an error is encountered. Basically, if the php script opens the result.txt and finds that its contents is "xxx", then it will task kill the exporting exe. Thinking this would work, I started compiling the pyw script. Frustratingly, after I started running the php script and it ran the exe, it got stuck waiting for the result.txt to change to either 100 or "xxx" again. The program won't even edit the result.txt. However, when I debugged its pyw script with vscode, it does the job. I also attempted to check if the program works without errors. It does.

I'm very confused. Why does it work in the pyw script but fails when it is an executable?

jr.prog
  • 69
  • 1
  • 13

1 Answers1

0

Try using sys.exit instead of exit to solve your issue. See this question for details about the difference between the two.

Sylvain
  • 85
  • 9