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

Add started event directly after process is started. #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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