def main(libc_name, n): import time import os from threading import Thread # if os.name == 'nt': from _ffi import WinDLL, types libc = WinDLL(libc_name) sleep = libc.getfunc('Sleep', [types.uint], types.uint) delays = [0]*n + [1000] else: from _ffi import CDLL, types libc = CDLL(libc_name) sleep = libc.getfunc('sleep', [types.uint], types.uint) delays = [0]*n + [1] # def loop_of_sleeps(i, delays): for delay in delays: sleep(delay) # ID: sleep # threads = [Thread(target=loop_of_sleeps, args=[i, delays]) for i in range(5)] start = time.time() for i, thread in enumerate(threads): thread.start() for thread in threads: thread.join() end = time.time() return end - start
def test_calling_convention2(self): if not self.iswin32: skip("windows specific") from _ffi import WinDLL, types kernel = WinDLL('Kernel32.dll') sleep = kernel.getfunc('Sleep', [types.uint], types.void) sleep(10)
def test_calling_convention1(self): if not self.iswin32: skip("windows specific") from _ffi import WinDLL, types libm = WinDLL(self.libm_name) pow = libm.getfunc('pow', [types.double, types.double], types.double) try: pow(2, 3) except ValueError, e: assert e.message.startswith('Procedure called with')