L0laapk3 / FactorioMaps

L0laapk3's FactorioMaps mod
https://mods.factorio.com/mod/L0laapk3_FactorioMaps
Other
121 stars 22 forks source link

psutil access denied #14

Closed OvermindDL1 closed 5 years ago

OvermindDL1 commented 5 years ago
Traceback (most recent call last):
  File "auto.py", line 339, in <module>
    auto(*sys.argv[1:])
  File "auto.py", line 250, in auto
    crop(outFolder, otherInputs[0], otherInputs[1], otherInputs[2], basepath)
  File "/home/overminddl1/Games/Factorio/tmp/mods/L0laapk3_FactorioMaps_2.4.2/crop.py", line 29, in crop
    psutil.Process(os.getpid()).nice(psutil.BELOW_NORMAL_PRIORITY_CLASS if os.name == 'nt' else -10)
  File "/home/overminddl1/.local/lib/python3.6/site-packages/psutil/__init__.py", line 716, in nice
    self._proc.nice_set(value)
  File "/home/overminddl1/.local/lib/python3.6/site-packages/psutil/_pslinux.py", line 1513, in wrapper
    raise AccessDenied(self.pid, self._name)
psutil._exceptions.AccessDenied: psutil.AccessDenied (pid=20832)

Wrapping the psutil calls with an exception handler and ignoring it (since it is only a nice thing and not anything required) fixes it.

However, the call itself is inherently wrong, right now it is:

psutil.Process(os.getpid()).nice(psutil.BELOW_NORMAL_PRIORITY_CLASS if os.name == 'nt' else -10)

-10 will give it more CPU power (less being 'nice' as per the name of the call), and to set a process to be less nice than 0 (default) requires having root permissions. I'm wondering if this was actually supposed to be 10 instead of -10 considering the windows version is set to BELOW_NORMAL_PRIORITY_CALL. Thus I ended up changing all the nice -10 values to 10 and that worked as well without needing an exception handler.

L0laapk3 commented 5 years ago

Yep, its definitely supposed to be 10 instead of -10, Thanks for that :p