Using Python binding Cpu__python on Windows

Source: Internet
Author: User

On the Windows platform, sometimes we want our program to run on a specified CPU, and I can see the following APIs to implement Win32process. Setprocessaffinitymask (hprocess, mask)-bind process to CPU Win32API. GetSystemInfo () [5]-Query The current machine has several CPU Win32API. GetCurrentProcess ()-Get current process information

Where the bound CPU is mask, the value is as follows:

0x0001 1
0x0002 2
0x0003 1 or 2
0x0004 3
0x0005 1 or 3
0x0006 2 or 3
0x0007 1, 2, or 3
0x000f 1, 2, 3, or 4
...

Example

Import win32process
import Win32API

# bound to CPU 1
win32process. Setprocessaffinitymask (Win32API. GetCurrentProcess (), 0x0001)

# bound to CPU 2
win32process. Setprocessaffinitymask (Win32API. GetCurrentProcess (), 0x0002)

# is bound to CPU 1 or 2
win32process. Setprocessaffinitymask (Win32API. GetCurrentProcess (), 0x0003)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.