|
18 | 18 | __author__ = 'Orsiris de Jong' |
19 | 19 | __copyright__ = 'Copyright (C) 2015-2025 Orsiris de Jong' |
20 | 20 | __licence__ = 'BSD 3 Clause' |
21 | | -__build__ = '2023122801' |
| 21 | +__build__ = '2025040901' |
22 | 22 |
|
23 | 23 |
|
24 | 24 | import sys |
@@ -679,17 +679,43 @@ def on_exit(): |
679 | 679 | assert ON_EXIT_CALLED is True, 'On exit was never called' |
680 | 680 |
|
681 | 681 |
|
682 | | -def test_priority(): |
683 | | - def check_nice(process): |
| 682 | +def test_low_priority(): |
| 683 | + def check_low_priority(process): |
684 | 684 | niceness = os.nice(process.pid) |
| 685 | + io_niceness = psutil.Process(process.pid).ionice() |
685 | 686 | if os.name == 'nt': |
686 | 687 | assert niceness == 16384, 'Process niceness not properly set: {}'.format(niceness) |
| 688 | + assert io_niceness == 1, 'Process io niceness not set properly: {}'.format(io_niceness) |
687 | 689 | else: |
688 | 690 | assert niceness == 15, 'Process niceness not properly set: {}'.format(niceness) |
| 691 | + assert io_niceness == 3, 'Process io niceness not set properly: {}'.format(io_niceness) |
689 | 692 | print('Nice !') |
690 | 693 |
|
691 | 694 | def command_runner_thread(): |
692 | | - return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_nice) |
| 695 | + return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_low_priority) |
| 696 | + |
| 697 | + |
| 698 | + thread = threading.Thread( |
| 699 | + target=command_runner_thread, args=() |
| 700 | + ) |
| 701 | + thread.daemon = True # thread dies with the program |
| 702 | + thread.start() |
| 703 | + |
| 704 | + |
| 705 | +def test_high_priority(): |
| 706 | + def check_high_priority(process): |
| 707 | + niceness = os.nice(process.pid) |
| 708 | + io_niceness = psutil.Process(process.pid).ionice() |
| 709 | + if os.name == 'nt': |
| 710 | + assert niceness == 128, 'Process niceness not properly set: {}'.format(niceness) |
| 711 | + assert io_niceness == 3, 'Process io niceness not set properly: {}'.format(io_niceness) |
| 712 | + else: |
| 713 | + assert niceness == -15, 'Process niceness not properly set: {}'.format(niceness) |
| 714 | + assert io_niceness == 1, 'Process io niceness not set properly: {}'.format(io_niceness) |
| 715 | + print('Nice !') |
| 716 | + |
| 717 | + def command_runner_thread(): |
| 718 | + return command_runner_threaded(PING_CMD, priority='low', io_priority='low', process_callback=check_high_priority) |
693 | 719 |
|
694 | 720 |
|
695 | 721 | thread = threading.Thread( |
|
0 commit comments