• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python forking.ForkingPickler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中multiprocessing.forking.ForkingPickler的典型用法代码示例。如果您正苦于以下问题:Python ForkingPickler类的具体用法?Python ForkingPickler怎么用?Python ForkingPickler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ForkingPickler类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: rebuild_ctype

def rebuild_ctype(type_, wrapper, length):
    if length is not None:
        type_ = type_ * length
    ForkingPickler.register(type_, reduce_ctype)
    obj = type_.from_address(wrapper.get_address())
    obj._wrapper = wrapper
    return obj
开发者ID:Aha00a,项目名称:play1,代码行数:7,代码来源:sharedctypes.py


示例2: rebuild_ctype

def rebuild_ctype(type_, wrapper, length):
    if length is not None:
        type_ = type_ * length
    ForkingPickler.register(type_, reduce_ctype)
    buf = wrapper.create_memoryview()
    obj = type_.from_buffer(buf)
    obj._wrapper = wrapper
    return obj
开发者ID:524777134,项目名称:cpython,代码行数:8,代码来源:sharedctypes.py


示例3: _feed

    def _feed(buffer, notempty, send_bytes, writelock, close, ignore_epipe):
        debug('starting thread to feed data to pipe')
        from .util import is_exiting

        nacquire = notempty.acquire
        nrelease = notempty.release
        nwait = notempty.wait
        bpopleft = buffer.popleft
        sentinel = _sentinel
        if sys.platform != 'win32':
            wacquire = writelock.acquire
            wrelease = writelock.release
        else:
            wacquire = None

        try:
            while 1:
                nacquire()
                try:
                    if not buffer:
                        nwait()
                finally:
                    nrelease()
                try:
                    while 1:
                        obj = bpopleft()
                        if obj is sentinel:
                            debug('feeder thread got sentinel -- exiting')
                            close()
                            return

                        # serialize the data before acquiring the lock
                        obj = ForkingPickler.dumps(obj)
                        if wacquire is None:
                            send_bytes(obj)
                        else:
                            wacquire()
                            try:
                                send_bytes(obj)
                            finally:
                                wrelease()
                except IndexError:
                    pass
        except Exception as e:
            if ignore_epipe and getattr(e, 'errno', 0) == errno.EPIPE:
                return
            # Since this runs in a daemon thread the resources it uses
            # may be become unusable while the process is cleaning up.
            # We ignore errors which happen after the process has
            # started to cleanup.
            try:
                if is_exiting():
                    info('error in queue thread: %s', e)
                else:
                    import traceback
                    traceback.print_exc()
            except Exception:
                pass
开发者ID:524777134,项目名称:cpython,代码行数:58,代码来源:queues.py


示例4: put

 def put(self, obj):
     # serialize the data before acquiring the lock
     obj = ForkingPickler.dumps(obj)
     if self._wlock is None:
         # writes to a message oriented win32 pipe are atomic
         self._writer.send_bytes(obj)
     else:
         with self._wlock:
             self._writer.send_bytes(obj)
开发者ID:524777134,项目名称:cpython,代码行数:9,代码来源:queues.py


示例5: get

 def get(self, block=True, timeout=None):
     if block and timeout is None:
         with self._rlock:
             res = self._recv_bytes()
         self._sem.release()
     else:
         if block:
             deadline = time.time() + timeout
         if not self._rlock.acquire(block, timeout):
             raise Empty
         try:
             if block:
                 timeout = deadline - time.time()
                 if timeout < 0 or not self._poll(timeout):
                     raise Empty
             elif not self._poll():
                 raise Empty
             res = self._recv_bytes()
             self._sem.release()
         finally:
             self._rlock.release()
     # unserialize the data after having released the lock
     return ForkingPickler.loads(res)
开发者ID:524777134,项目名称:cpython,代码行数:23,代码来源:queues.py


示例6: recv_handle

    new_handle = recv_handle(conn)
    conn.close()
    return new_handle


def reduce_connection(conn):
    rh = reduce_handle(conn.fileno())
    return (rebuild_connection, (rh, conn.readable, conn.writable))


def rebuild_connection(reduced_handle, readable, writable):
    handle = rebuild_handle(reduced_handle)
    return _multiprocessing.Connection(handle, readable=readable, writable=writable)


ForkingPickler.register(_multiprocessing.Connection, reduce_connection)

def fromfd(fd, family, type_, proto = 0):
    s = socket.fromfd(fd, family, type_, proto)
    if s.__class__ is not socket.socket:
        s = socket.socket(_sock=s)
    return s


def reduce_socket(s):
    reduced_handle = reduce_handle(s.fileno())
    return (rebuild_socket, (reduced_handle,
      s.family,
      s.type,
      s.proto))
开发者ID:webiumsk,项目名称:WOT-0.9.15-CT,代码行数:30,代码来源:reduction.py


示例7:

            if timeout <= 0:
                return select.select(object_list, [], [], 0)[0]
            else:
                deadline = time.time() + timeout
        while True:
            try:
                return select.select(object_list, [], [], timeout)[0]
            except OSError as e:
                if e.errno != errno.EINTR:
                    raise
            if timeout is not None:
                timeout = deadline - time.time()

#
# Make connection and socket objects sharable if possible
#

if sys.platform == 'win32':
    from . import reduction
    ForkingPickler.register(socket.socket, reduction.reduce_socket)
    ForkingPickler.register(Connection, reduction.reduce_connection)
    ForkingPickler.register(PipeConnection, reduction.reduce_pipe_connection)
else:
    try:
        from . import reduction
    except ImportError:
        pass
    else:
        ForkingPickler.register(socket.socket, reduction.reduce_socket)
        ForkingPickler.register(Connection, reduction.reduce_connection)
开发者ID:Patsy63,项目名称:python-3.3,代码行数:30,代码来源:connection.py


示例8: recv

 def recv(self):
     """Receive a (picklable) object"""
     self._check_closed()
     self._check_readable()
     buf = self._recv_bytes()
     return ForkingPickler.loads(buf.getbuffer())
开发者ID:jadore,项目名称:cpython,代码行数:6,代码来源:connection.py


示例9: send

 def send(self, obj):
     """Send a (picklable) object"""
     self._check_closed()
     self._check_writable()
     self._send_bytes(ForkingPickler.dumps(obj))
开发者ID:jadore,项目名称:cpython,代码行数:5,代码来源:connection.py



注:本文中的multiprocessing.forking.ForkingPickler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forking.Popen类代码示例发布时间:2022-05-27
下一篇:
Python forking.duplicate函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap