當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。