On Sat, 25 Mar 2017 09:46:38 +0900 Takashi Yano wrote: > from ctypes import pythonapi > key = pythonapi.PyThread_create_key() > res1 = pythonapi.PyThread_set_key_value(key, 5555) > res2 = pythonapi.PyThread_get_key_value(key) > res3 = pythonapi.PyThread_delete_key(key) > print(key,res1,res2,res3) There was one mistake. The function type of PyThread_delete_key() is void, so the return value is meaningless (just a garbage). Moreover, the script works as expected if modified as follows. --- from here --- from ctypes import * pythonapi.PyThread_create_key.restype = c_long pythonapi.PyThread_set_key_value.argtypes = [c_long, c_void_p] pythonapi.PyThread_get_key_value.restype = c_void_p pythonapi.PyThread_get_key_value.argtypes = [c_long] key = pythonapi.PyThread_create_key() res1 = pythonapi.PyThread_set_key_value(key, 5555) res2 = pythonapi.PyThread_get_key_value(key) print(key,res1,res2) --- to here --- This is because 3.6-thread-cygwin64.patch is changing the type of functions as the key type is changed from int to long. However, from the portability point of view, it is not desirable to change the types of functions exported as APIs. If one of the idea of the patches I proposed will be employed, the patch 3.6-thread-cygwin64.patch is not necessary anymore. Thus, I would like to propose new version of the patches replacing 3.6-thread-cygwin64.patch. 3.6-thread-cygwin-replacement-1.patch: replaces 3.6-thread-cygwin64.patch and pthread-cygwin-1.patch 3.6-thread-cygwin-replacement-2.patch: replaces 3.6-thread-cygwin64.patch and pthread-cygwin-2.patch I would appreciate your comment. -- Takashi Yano