Skip to content

Instantly share code, notes, and snippets.

@tlynn
tlynn / affinity.py
Last active June 22, 2020 03:02
Use cffi (cffi.rtfd.org) to wrap the pthread set/get affinity functions.
'''
Wrap the functions to tie threads to particular CPU cores (affinity) on Linux.
'''
import os
import cffi
__all__ = ['pthread_self', 'pthread_getaffinity_np', 'pthread_setaffinity_np']