Exemplo n.º 1
0
def get_queue(qid=None):
    r"""Create or return a sysv_ipc.MessageQueue and register it.

    Args:
        qid (int, optional): If provided, ID for existing queue that should be
           returned. Defaults to None and a new queue is returned.

    Returns:
        :class:`sysv_ipc.MessageQueue`: Message queue.

    """
    if _ipc_installed:
        kwargs = dict(max_message_size=tools.get_YGG_MSG_MAX())
        if qid is None:
            kwargs['flags'] = sysv_ipc.IPC_CREX
        try:
            mq = sysv_ipc.MessageQueue(qid, **kwargs)
        except sysv_ipc.ExistentialError as e:  # pragma: debug
            raise sysv_ipc.ExistentialError("%s: %s" % (e, qid))
        key = str(mq.key)
        IPCComm.register_comm(key, mq)
        return mq
    else:  # pragma: windows
        logger.warning("IPC not installed. Queue cannot be returned.")
        return None
Exemplo n.º 2
0
import pytest
import os
import numpy as np
import flaky
import copy
from yggdrasil.communication import get_comm
from yggdrasil.interface import YggInterface
from yggdrasil import constants
from yggdrasil.tools import get_YGG_MSG_MAX, is_lang_installed
from yggdrasil.components import import_component
from yggdrasil.drivers import ConnectionDriver
from tests import TestClassBase as base_class

YGG_MSG_MAX = get_YGG_MSG_MAX()


class ModelEnv(object):
    def __init__(self, language=None, **new_kw):
        new_kw['YGG_SUBPROCESS'] = 'True'
        if language is not None:
            new_kw['YGG_MODEL_LANGUAGE'] = language
        # Send environment keyword to fake language
        self.old_kw = {}
        for k, v in new_kw.items():
            self.old_kw[k] = os.environ.get(k, None)
            os.environ[k] = v

    def __enter__(self):
        return None

    def __exit__(self, type, value, traceback):
Exemplo n.º 3
0
import os
from yggdrasil import tools
from yggdrasil.communication.DefaultComm import DefaultComm


YGG_MSG_MAX = tools.get_YGG_MSG_MAX()
YGG_MSG_EOF = tools.YGG_MSG_EOF
YGG_MSG_BUF = tools.YGG_MSG_BUF
YGG_SERVER_INPUT = os.environ.get('YGG_SERVER_INPUT', False)
YGG_SERVER_OUTPUT = os.environ.get('YGG_SERVER_OUTPUT', False)
YGG_MODEL_NAME = os.environ.get('YGG_MODEL_NAME', False)
_global_scope_comms = {}


def maxMsgSize():
    r"""int: The maximum message size."""
    return YGG_MSG_MAX


def bufMsgSize():
    r"""int: Buffer size for average message."""
    return YGG_MSG_BUF


def eof_msg():
    r"""str: Message signalling end of file."""
    return YGG_MSG_EOF


def YggInit(_type, args=None, kwargs=None):
    r"""Short interface to identify functions called by another language.