try:
import ctypes, ctypes.util
# The uuid_generate_* routines are provided by libuuid on at least
# Linux and FreeBSD, and provided by libc on Mac OS X.
for libname in ['uuid', 'c']:
try:
lib = ctypes.CDLL(ctypes.util.find_library(libname))
except:
continue
if hasattr(lib, 'uuid_generate_random'):
_uuid_generate_random = lib.uuid_generate_random
if hasattr(lib, 'uuid_generate_time'):
_uuid_generate_time = lib.uuid_generate_time
問體點在 try 區塊裡。程式本身邏輯是對的,但是 PyPy3 有 bug,當執行
try:
import ctypes, ctypes.util
# The uuid_generate_* routines are provided by libuuid on at least
# Linux and FreeBSD, and provided by libc on Mac OS X.
for libname in ['uuid', 'c']:
try:
name = ctypes.util.find_library(libname)
if name is None:
continue
lib = ctypes.CDLL(name)
except:
continue
if hasattr(lib, 'uuid_generate_random'):
_uuid_generate_random = lib.uuid_generate_random
if hasattr(lib, 'uuid_generate_time'):
_uuid_generate_time = lib.uuid_generate_time
這並沒有完全解決問題,如果找不到指定的模組,一樣會因為錯誤訊息含有 Unicode 而當掉。如果還是不行的話,嘗試把整個 try except 砍掉吧,這在我的電腦上一樣有用
沒有留言:
張貼留言