当前位置: 首页>>代码示例>>Python>>正文


Python pool.MaybeEncodingError方法代码示例

本文整理汇总了Python中multiprocessing.pool.MaybeEncodingError方法的典型用法代码示例。如果您正苦于以下问题:Python pool.MaybeEncodingError方法的具体用法?Python pool.MaybeEncodingError怎么用?Python pool.MaybeEncodingError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.pool的用法示例。


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

示例1: test_unpickleable_result

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def test_unpickleable_result(self):
        from multiprocessing.pool import MaybeEncodingError
        p = multiprocessing.Pool(2)

        # Make sure we don't lose pool processes because of encoding errors.
        for iteration in range(20):

            scratchpad = [None]
            def errback(exc):
                scratchpad[0] = exc

            res = p.apply_async(unpickleable_result, error_callback=errback)
            self.assertRaises(MaybeEncodingError, res.get)
            wrapped = scratchpad[0]
            self.assertTrue(wrapped)
            self.assertIsInstance(scratchpad[0], MaybeEncodingError)
            self.assertIsNotNone(wrapped.exc)
            self.assertIsNotNone(wrapped.value)

        p.close()
        p.join() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:_test_multiprocessing.py

示例2: main

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def main():
    client = Elasticsearch()

    create_db(cursor)
    clear_db(conn, cursor)

    try:
        logging.info(f'Getting photo URL...')
        pool = Pool(NUM_WORKERS, init_worker)
        data = pool.imap_unordered(_http_get, get_pictures(client))
    except KeyboardInterrupt:
        pool.terminate()
        pool.join()
        raise SystemExit(1)
    except MaybeEncodingError:
        pass

    insert_sqlite_data(data)
    update_es_data(cursor, client)

    conn.close() 
开发者ID:olhoneles,项目名称:politicos,代码行数:23,代码来源:update_politician_pictures.py

示例3: test_unpickleable_result

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def test_unpickleable_result(self):
        from multiprocessing.pool import MaybeEncodingError
        p = multiprocessing.Pool(2)

        # Make sure we don't lose pool processes because of encoding errors.
        for iteration in range(20):
            res = p.apply_async(unpickleable_result)
            self.assertRaises(MaybeEncodingError, res.get)

        p.close()
        p.join() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_multiprocessing.py

示例4: __init__

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def __init__(self, exc, value):
            self.exc = repr(exc)
            self.value = repr(value)
            super(MaybeEncodingError, self).__init__(self.exc, self.value) 
开发者ID:CleanCut,项目名称:green,代码行数:6,代码来源:process.py

示例5: __repr__

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def __repr__(self):
            return "<MaybeEncodingError: %s>" % str(self)


# Python 2 and 3 raise a different error when they exit 
开发者ID:CleanCut,项目名称:green,代码行数:7,代码来源:process.py

示例6: worker

# 需要导入模块: from multiprocessing import pool [as 别名]
# 或者: from multiprocessing.pool import MaybeEncodingError [as 别名]
def worker(
    inqueue,
    outqueue,
    initializer=None,
    initargs=(),
    maxtasks=None,
    wrap_exception=False,
    finalizer=None,
    finalargs=(),
):  # pragma: no cover
    assert maxtasks is None or (type(maxtasks) == int and maxtasks > 0)
    put = outqueue.put
    get = inqueue.get
    if hasattr(inqueue, "_writer"):
        inqueue._writer.close()
        outqueue._reader.close()

    if initializer is not None:
        try:
            initializer(*initargs)
        except InitializerOrFinalizerError as e:
            print(str(e))

    completed = 0
    while maxtasks is None or (maxtasks and completed < maxtasks):
        try:
            task = get()
        except (EOFError, PortableOSError):
            util.debug("worker got EOFError or OSError -- exiting")
            break

        if task is None:
            util.debug("worker got sentinel -- exiting")
            break

        job, i, func, args, kwds = task
        try:
            result = (True, func(*args, **kwds))
        except Exception as e:
            if wrap_exception:
                e = ExceptionWithTraceback(e, e.__traceback__)
            result = (False, e)
        try:
            put((job, i, result))
        except Exception as e:
            wrapped = MaybeEncodingError(e, result[1])
            util.debug("Possible encoding error while sending result: %s" % (wrapped))
            put((job, i, (False, wrapped)))
        completed += 1

    if finalizer:
        try:
            finalizer(*finalargs)
        except InitializerOrFinalizerError as e:
            print(str(e))

    util.debug("worker exiting after %d tasks" % completed)


# Unmodified (see above) 
开发者ID:CleanCut,项目名称:green,代码行数:62,代码来源:process.py


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