3

I am very much a novice at Python.

I am running a Tkinter GUI on Windows 7 and Windows 10. I have a subprocess running a data logger routine at 1 KHz. I would like to set a cpu affinity for the subprocess,

I am building with Python 3.8.

PEJ
  • 31
  • 2
  • Are you looking for something [like this](https://docs.python.org/3/library/os.html#os.sched_setaffinity) – Thingamabobs Nov 07 '21 at 16:51
  • I need to find the process id for the datalogger subprocess then I think it will work Thanks. – PEJ Nov 07 '21 at 19:18
  • 1
    I have used sched_setaffinity from the sched.h library in Linux but am not sure how it will work in Python. I will let you know. – PEJ Nov 07 '21 at 19:33
  • 1
    It appears that the os.sched_setaffinity(pid, mask) function is available on Unix/Linux only. – PEJ Nov 07 '21 at 20:32
  • This seems a bit more complicated than I thought. I guess you need to go with pywin32 to get the [CurrentProcess](http://timgolden.me.uk/pywin32-docs/win32process__GetCurrentProcess_meth.html) and I guess you are looking for [SetProcessPriorityBoost](http://timgolden.me.uk/pywin32-docs/win32process__SetProcessPriorityBoost_meth.html) which will have this [behavior](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setprocesspriorityboost). Take a look at [win32process](http://timgolden.me.uk/pywin32-docs/win32process.html) – Thingamabobs Nov 07 '21 at 21:01
  • 1
    [Get](http://timgolden.me.uk/pywin32-docs/win32process__GetProcessAffinityMask_meth.html) and [SetPriorityMask](http://timgolden.me.uk/pywin32-docs/win32process__SetProcessAffinityMask_meth.html) are also available, to have your [process in specific kernel](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setprocesspriorityboost) – Thingamabobs Nov 07 '21 at 21:06
  • Thanks. I will check that out. – PEJ Nov 09 '21 at 19:48

1 Answers1

0

You can use the psutil library. This answer should help you.

lfamorim
  • 11
  • 2