#!/usr/bin/env python #from __future__ import print_function import ctypes import threading lib = ctypes.CDLL('./lib.so') callback_t = ctypes.CFUNCTYPE(None) lib.callback.argtypes = [ callback_t ] lib.callback.restype = ctypes.c_int lc = threading.local() def callback_fn(): if hasattr(lc, 'x'): print("Python callback_fn called, lc.x = %d" % lc.x) else: lc.x = 42 print("Python callback_fn called, setting lc.x = %d" % lc.x) res = lib.callback(callback_t(callback_fn)) if res != 0: raise SystemExit('lib.callback() failed')