[英]Porting Python 2 code that uses _multiprocessing
我目前正在將一些用pypy運行的Python 2代碼移植到python 3上。由於使用該文檔很難找到使用_multiprocessing
代碼,因此我有些_multiprocessing
。
from _multiprocessing import address_of_buffer
#example usage
def buffer_info(self):
return address_of_buffer(self._mmap)[0], self._size
當我嘗試在Python3.4中使用此代碼時,導入出現問題:
ImportError: cannot import name 'address_of_buffer'
快速瀏覽Python 3文檔https://docs.python.org/3/library/multiprocessing.html之后,我沒有看到直接替代它的信息。 移植此代碼的最佳方法是什么?
您可以使用ctypes:
def address_of_buffer(buf):
return ctypes.addressof(ctypes.c_char.from_buffer(buf))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.