Skip to content

Instantly share code, notes, and snippets.

@Andrei-Pozolotin
Created December 6, 2019 15:50
Show Gist options
  • Save Andrei-Pozolotin/14187e1c61e0fa56866077c5acfd92ce to your computer and use it in GitHub Desktop.
Save Andrei-Pozolotin/14187e1c61e0fa56866077c5acfd92ce to your computer and use it in GitHub Desktop.
nice_1.py
master nice=0
worker index=1 nice=19
worker index=2 nice=19
worker index=3 nice=19
worker index=4 nice=19
worker index=5 nice=19
worker index=6 nice=19
worker index=7 nice=19
worker index=8 nice=19
worker index=9 nice=19
...
ratio=[11, 9, 10, 8, 8, 11, 10, 10, 9, 9]
ratio=[11, 9, 10, 8, 8, 11, 10, 10, 9, 9]
ratio=[11, 9, 10, 8, 8, 11, 10, 10, 9, 9]
ratio=[11, 9, 11, 8, 8, 11, 10, 10, 9, 9]
ratio=[11, 9, 11, 8, 8, 11, 10, 10, 9, 9]
#!/usr/bin/env python
import os
import time
import threading
thread_count = 10
def nice_perf():
""
count_list = [0 for _ in range(thread_count)]
def master_proc():
""
nice = os.nice(+0)
print(f"master nice={nice}")
while True:
count_list[0] += 1
def worker_proc(index:int):
""
nice = os.nice(+100)
print(f"worker index={index} nice={nice}")
while True:
count_list[index] += 1
master_thread = threading.Thread(target=master_proc, daemon=True)
master_thread.setName("master")
master_thread.start()
for index in range(1, thread_count):
worker_thread = threading.Thread(target=worker_proc, daemon=True, args=(index,))
worker_thread.setName("worker")
worker_thread.start()
while True:
time.sleep(1)
total = sum(count_list)
ratio = [int(100 * entry / total) for entry in count_list]
print(f"ratio={ratio}")
nice_perf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment