From: Neal Becker (ndbecker2_at_gmail.com)
Date: Wed Jan 30 2008 - 03:18:53 PST
1 question: Not sure whether to the GIL should be released during the call or not. I'm not using any multi-threading, so I think it doesn't matter? from __future__ import with_statement from ctypes import * from errno import * import os def die (msg): abort (msg) class cr_checkpoint_args_t (Structure): _fields_ = [("cr_version", c_int), ("cr_scope", c_int), ("cr_target", c_int), ("cr_fd", c_int), ("cr_signal", c_int), ("cr_timeout", c_int), ("cr_flags", c_int)] libcr = CDLL ('/usr/lib64/libcr.so.0') cr_args = cr_checkpoint_args_t() cr_args.cr_version = 1 CR_SCOPE_PROC = 1 libcr.cri_initialize_checkpoint_args_t (byref(cr_args)) cr_args.cr_scope = CR_SCOPE_PROC cr_args.cr_target = 0 cr_args.cr_signal = 0 cr_args.cr_timeout = 0 cr_args.cr_flags = 0 _id = libcr.cr_init() assert (_id >= 0) def request_checkpoint (cr_args, cr_handle): assert (isinstance (cr_args, cr_checkpoint_args_t)) assert (isinstance (cr_handle, c_ulong)) # c long err = libcr.cr_request_checkpoint (byref(cr_args), byref (cr_handle)) return err, cr_handle cr_handle = c_ulong() with open ("checkpoint", 'w') as cp_file: cr_args.cr_fd = cp_file.fileno() err,cr_handle = request_checkpoint (cr_args, cr_handle) err = -1 while (err < 0): err = libcr.cr_poll_checkpoint (byref(cr_handle), POINTER(c_int)()) print "err:", os.strerror(err) if (err < 0): if (errno == EINVAL): break # restarted elif (errno == EINTR): continue else: die ("cr_poll_checkpoint") elif (err == 0): die ("cr_poll_checkpoint returned unexpected 0")