Skip to content

Conversation

@dmcken
Copy link

@dmcken dmcken commented Oct 7, 2024

I have a similar issue to #61 where I want to change the priority of the FFMpeg process.

The problem I see is there are too many options available and in my humble opinion I don't think its something this library should get involved with. The steps are different:

  • Windows you drop the current process's priority and then raise back to normal after.
  • Linux doesn't allow you to raise yourself back to normal if you do drop your priority so the windows pattern doesn't work.
  • I can't speak to Mac, Solaris or other platforms at this point.

From a chunk of my code that handles Windows and Linux:

if psutil.WINDOWS:
    psutil.Process().nice(PRIORITY_LOWER)
    prog_h = subprocess.Popen(
        call_params,
        stdin=subprocess.PIPE,
        stdout=f_stdout,
        stderr=subprocess.STDOUT,
    )
    psutil.Process().nice(PRIORITY_NORMAL)
elif psutil.LINUX:
    # PermissionError is thrown when attempting to return to the normal
    # priority that is being done above on windows.
    # We are since python 3.3 able to just set the priority of the ffmpeg
    # process directly so this will likely become the default going
    # forward.
    prog_h = subprocess.Popen(
        call_params,
        stdin=subprocess.PIPE,
        stdout=f_stdout,
        stderr=subprocess.STDOUT,
    )
    os.setpriority(os.PRIO_PROCESS, prog_h.pid, PRIORITY_LOWER)

So I recommend a started event that occurs directly after process start, which together with the existing start event can allow the user to use whatever library they want in at least these two scenarios (I expect since the user can put whatever code they want directly before and after the process creation it should cover other scenarios as well).

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.

1 participant