Controlling scheduling priority of python threads?

前端 未结 5 536
余生分开走
余生分开走 2020-12-14 16:31

I\'ve written a script that uses two thread pools of ten threads each to pull in data from an API. The thread pool implements this code on ActiveState. Each thread pool is

5条回答
  •  悲哀的现实
    2020-12-14 17:13

    It doesn't work, but I tried:

    1. getting the parent pid and priority
    2. launching threads using concurrent.futures.ThreadPoolExecutor
    3. using ctypes to get the (linux) thread id from within the thread(works)
    4. using the tid with os.setpriority(os.PRIO_PROCESS,tid,parent_priority+1)
    5. calling pool.shutdown() from the parent.

    Even with liberal sprinkling of os.sched_yield(), the child threads never actually run past the setpriority().

    Reading man pages, it seems threads don't have the capability to change (even their) scheduling priority; you have to do something with "capabilities" to give the thread the "CAP_SYS_NICE" capability. Running the process with root permissions didn't help either; child threads still don't run.

提交回复
热议问题