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


Python BaseManager.get_queue方法代码示例

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


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

示例1: Communicate

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import get_queue [as 别名]
class Communicate(object):
    """Library for communication between processes.
    For example this can be used to handle communication between processes of the Parallel robot library.
    
    Requires Python 2.6
    
    Example:
    
    Process 1 test file:
    | *Settings* |
    | Library | Communicate |
    
    
    | *Test Cases* |
    | Communicator |
    |        | [Setup] | Start Communication Service |
    |        | Send Message To | my message queue     | hello world!        |
    |        | ${message}=     | Receive Message From | other message queue |
    |        | Should Be Equal | ${message}           | hello!              |
    |        | [Teardown] | Stop Communication Service |
    
    Process 2 test file:
    | *Settings* |
    | Library | Communicate | ${process 1 ip address if on a different machine} |
    
    
    | *Test Cases* |
    | Helloer |
    |         | ${message}= | Receive Message From | my message queue |
    |         | Should Be Equal | ${message}          | hello world!  |
    |         | Send Message To | other message queue | hello!        |
    
    """

    def __init__(self, address='127.0.0.1', port=2187):
        """
        `address` of the communication server.
        `port` of the communication server.
        """
        self._address = address
        self._port = int(port)
        self._authkey = 'live long and prosper'
        self._queue = None
        self._connected = False

    def _connect(self):
        self._create_manager().connect()
        self._connected = True

    def start_communication_service(self):
        """Starts a communication server that will be used to share messages and objects between processes.
        """
        self._create_manager(_create_caching_getter(Queue),
                             _create_caching_getter(Event)).start()
        self._connected = True

    def stop_communication_service(self):
        """Stops a started communication server. 
        This ensures that the server and the messages that it has don't influence the next tests.
        To ensure that this keyword really happens place this in the teardown section.
        """
        self._manager.shutdown()
        self._connected = False

    def _create_manager(self, queue_getter=None, event_getter=None):
        BaseManager.register('get_queue', queue_getter)
        BaseManager.register('get_event', event_getter)
        self._manager = BaseManager((self._address, self._port), self._authkey)
        return self._manager

    def send_message_to(self, queue_id, value):
        """Send a message to a message queue.

        `queue_id` is the identifier for the queue.

        `value` is the message. This can be a string, a number or any serializable object.

        Example:
        In one process
        | Send Message To | my queue | hello world! |
        ...
        In another process
        | ${message}= | Receive Message From | my queue |
        | Should Be Equal | ${message} | hello world! |
        """
        self._get_queue(queue_id).put(value)

    def receive_message_from(self, queue_id, timeout=None):
        """Receive and consume a message from a message queue.
        By default this keyword will block until there is a message in the queue.

        `queue_id` is the identifier for the queue.

        `timeout` is the time out in seconds to wait.

        Returns the value from the message queue. Fails if timeout expires.

        Example:
        In one process
        | Send Message To | my queue | hello world! |
#.........这里部分代码省略.........
开发者ID:Senseg,项目名称:robotframework,代码行数:103,代码来源:Communicate.py

示例2: RuntimeError

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import get_queue [as 别名]
if monkey_code not in monkey_folders:
    raise RuntimeError("Monkey specified in profile does not exist.")

exec "import monkeys.%s.monkey as monkey_module" % monkey_code
monkey = monkey_module.Monkey(profile["parameters"])

if profile["measure_privacy"]:
    client = MongoClient(profile["host_ip"], profile["mongo_port"])
    mobile_privacy_research_db = client.mobile_privacy_research
    runs = mobile_privacy_research_db.runs

    BaseManager.register('get_queue')
    m = BaseManager(address=(profile["host_ip"], profile["request_queue_port"]), authkey='')
    m.connect()
    request_queue = m.get_queue()
    utils.clear_queue(request_queue)

# connect to ADB
d = Device(profile["device_id"])
utils.log("Connected to Android device")

apk_files = [x.replace("\n","") for x in open(profile["apk_list"]).readlines()]

for apk_file in apk_files:
    package_name = apk_file.replace("\n","")
    if "apk_dir" in profile:
        package_name = profile["apk_dir"] + "/" + package_name
    package_title = package_name.split("/")[-1].replace(".apk","")

    if "repeat" in profile and not profile["repeat"]:
开发者ID:shbhrsaha,项目名称:mobile-privacy-thesis,代码行数:32,代码来源:chimp.py

示例3: BaseManager

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import get_queue [as 别名]
"""
    Processes mitmdump requests into a shared queue

    Usage:
        mitmdump trace.py
"""

from multiprocessing.managers import BaseManager
import cgi
import urlparse
import pickle

BaseManager.register('get_queue')
m = BaseManager(address=('127.0.0.1', 50000), authkey='')
m.connect()
queue = m.get_queue()

def request(context, flow):
    serialized_request = pickle.dumps(flow.request)
    queue.put(serialized_request)

    """
    method = flow.request.method
    scheme = flow.request.scheme
    host = flow.request.host
    path = flow.request.path
    content = flow.request.content
    headers = flow.request.headers

    url = scheme + "://" + host + path
    url_data_dict = cgi.parse_qs(urlparse.urlparse(url).query)
开发者ID:shbhrsaha,项目名称:mobile-privacy-thesis,代码行数:33,代码来源:trace.py


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