Search code examples
pythonnice

How to use nice command in python?


How to use nice in python ?

I have a simple bash script:

nice -n 9 cp /var/tmp/1 /var/tmp/2

What will be python alternative?


Solution

  • In pure Python, you can use os.nice and shutil.copy (or shutil.copyfile if you do not need to preserve file metadata):

    import os
    import shutil
    
    os.nice(9)
    shutil.copy('/var/tmp/1', '/var/tmp/2')