Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use psutil.Process to track and terminate factorio #103

Closed
wants to merge 1 commit into from

Conversation

saulrh
Copy link

@saulrh saulrh commented Jul 15, 2021

Polling psutil.process_exists and manually invoking things like killall factorio can have some pretty nasty bugs if PIDs are reused or factorio exits before we expect. psutil protects us from all of this. It also means we don't have to write our own platform-specific code to kill factorio.

Should fix #102. That said, while this works on my machine (:tm:) I'm sure there was some reason #37 was raised, so it might be useful to track down some more information about how factorio behaves when invoked. It feels weird that factorio would try to daemonize itself, though.

Polling psutil.process_exists, and manually invoking things like
`killall factorio`, can have some pretty nasty bugs if PIDs are reused
or factorio exits before we expect. psutil us from all of this. It
also means we don't have to write our own platform-specific code to
kill factorio.

Should fix L0laapk3#102.
@saulrh
Copy link
Author

saulrh commented Jul 15, 2021

Another 6 hours running FactorioMaps flat-out on my biggest box says that this probably did not fix #102, but it still appears to have cleaned things up quite a bit. I'm starting to suspect that factorio is doing something like throwing away the termination request rather than queueing it for after screenshots are done.

Is there a way to figure out the current tick on a save without starting Factorio up to read and execute it? If we can figure out the current tick, we could probably use factorio's --until-tick argument to ensure termination.

@L0laapk3
Copy link
Owner

L0laapk3 commented Jul 15, 2021

Is there a way to figure out the current tick on a save without starting Factorio up to read and execute it? If we can figure out the current tick, we could probably use factorio's --until-tick argument to ensure termination.

I have explored this option, and iirc its possible to extract it from the raw savefile and I was able find it in there, however the reason I avoided this is that the savefile is just raw serialized data and the location of the tick value in a savefile could change with any minor update.

One thing I have not tried is stuff like --until-tick 0 and then hope it runs a single tick :p

@L0laapk3
Copy link
Owner

I'm starting to suspect that factorio is doing something like throwing away the termination request rather than queueing it for after screenshots are done.
From what I can tell, set_wait_for_screenshots_to_finish() simply blocks the main thread in the render function until all the screenshotting threads are finished.
Normally, if you send 1 termination request to factorio, it will print something in the log along the lines of "finishing up and safe exit" and allows it to finish the current tick I believe, and if you send a second termination request it will print something else in the log and terminate immediately. I only send a single request and it should show up in the log (--verbosegame)

@saulrh saulrh closed this Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants