How to use the tblib.pickling_support.install function in tblib

To help you get started, we’ve selected a few tblib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github standy66 / purerpc / src / purerpc / test_utils.py View on Github external
import multiprocessing
import multiprocessing.connection
import tempfile
import shutil
import os
import sys
import inspect
import importlib
import concurrent.futures
import contextlib
import time
import random
import string

from tblib import pickling_support
pickling_support.install()

import forge
import anyio
from async_generator import aclosing


@contextlib.contextmanager
def compile_temp_proto(*relative_proto_paths):
    modules = []
    with tempfile.TemporaryDirectory() as temp_dir:
        sys.path.insert(0, temp_dir)
        try:
            for relative_proto_path in relative_proto_paths:
                proto_path = os.path.join(os.path.dirname(
                    inspect.currentframe().f_back.f_back.f_globals['__file__']),
                    relative_proto_path)
github scientifichackers / zproc / zproc / zproc_server.py View on Github external
import os
import pickle
from typing import Tuple
import uuid
from copy import deepcopy

import zmq
from tblib import pickling_support

from zproc import util

# installs pickle support for exceptions.
pickling_support.install()


class ZProcServer:
    def __init__(self, server_address: Tuple[str, str], address_queue):
        self.state = {}

        self.zmq_ctx = zmq.Context()
        self.zmq_ctx.setsockopt(zmq.LINGER, 0)

        self.router_sock = self.zmq_ctx.socket(zmq.ROUTER)
        self.publish_sock = self.zmq_ctx.socket(zmq.PUB)

        if server_address is None:
            if os.system == "posix":
                base_address = "ipc://" + str(util.ipc_base_dir)
                self.req_rep_address, self.pub_sub_address = (
github xnd-project / rbc / rbc / thrift / server.py View on Github external
import time
import multiprocessing
import sys
import pickle
from . import utils
import thriftpy2 as thr
import thriftpy2.rpc

try:
    import tblib
    import tblib.pickling_support
except ImportError:
    tblib = None

if tblib is not None:
    tblib.pickling_support.install()


class Processor(thr.thrift.TProcessor):

    def __init__(self, server, service, handler):
        self.server = server
        thr.thrift.TProcessor.__init__(self, service, handler)

    def handle_exception(self, e, result):
        if thr.thrift.TProcessor.handle_exception(self, e, result):
            return True
        # map Python native exception to thrift Exception so that
        # client can remap thrift Exception to Python

        exc_type = self.server.thrift.Exception
        if tblib is not None:
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / multi_model_broadcast.py View on Github external
import uuid

import multiprocessing as mp
import tblib.pickling_support


import zmq
from zmq.eventloop import ioloop, zmqstream

from gnome import GnomeId
from gnome.environment import Wind
from gnome.outputters import WeatheringOutput


# allows us to pickle exception traceback info
tblib.pickling_support.install()


class ModelConsumer(mp.Process):
    '''
        This is a consumer process that makes the model available
        upon process creation so that registered commands can act upon
        the model.
        Program flow:
        - Read a command from the task queue
        - if there is a None command, we exit the process.
        - Parse the data received in the format:
            ('registeredcommand', {arg1: val1,
                                   arg2: val2,
                                   ...
                                   },
             )
github pybuilder / pybuilder / src / main / python / pybuilder / utils.py View on Github external
"""
    Forks a child, making sure that all exceptions from the child are safely sent to the parent
    If a target raises an exception, the exception is re-raised in the parent process
    @return tuple consisting of process exit code and target's return value
    """
    if is_windows():
        logger.warn(
            "Not forking for %s due to Windows incompatibilities (see #184). "
            "Measurements (coverage, etc.) might be biased." % target)
        return fake_windows_fork(group, target, name, args, kwargs)
    try:
        sys.modules["tblib.pickling_support"]
    except KeyError:
        import tblib.pickling_support

        tblib.pickling_support.install()

    q = SimpleQueue()

    def instrumented_target(*args, **kwargs):
        ex = tb = None
        try:
            send_value = (target(*args, **kwargs), None, None)
        except:
            _, ex, tb = sys.exc_info()
            send_value = (None, ex, tb)

        try:
            q.put(send_value)
        except:
            _, send_ex, send_tb = sys.exc_info()
            e_out = Exception(str(send_ex), send_tb, None if ex is None else str(ex), tb)
github scientifichackers / zproc / zproc / server.py View on Github external
import os
import signal
from collections import defaultdict
from copy import deepcopy
from typing import Any, Dict

import itsdangerous
import zmq
from tblib import pickling_support

from zproc import util, exceptions
from zproc.constants import Msgs, Commands

pickling_support.install()


class Server(util.SecretKeyHolder):
    _active_identity = b""
    _active_namespace = b""
    _active_state = {}  # type:dict

    def __init__(self, server_address: str, send_conn, secret_key: str = None) -> None:
        super().__init__(secret_key)

        self.zmq_ctx = util.create_zmq_ctx()

        self.router_sock = self.zmq_ctx.socket(zmq.ROUTER)
        self.pub_sock = self.zmq_ctx.socket(zmq.PUB)
        self.pull_sock = self.zmq_ctx.socket(zmq.PULL)