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


Python Engine.instance方法代码示例

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


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

示例1: install

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
def install(app=None, timeout=0.02):
    """
    Creates a :class:`~PySide.QtCore.QTimer` instance that will be triggered
    continuously to call :func:`Engine.poll() <pants.engine.Engine.poll>`,
    ensuring that Pants remains responsive.

    =========  ========  ============
    Argument   Default   Description
    =========  ========  ============
    app        None      *Optional.* The :class:`~PySide.QtCore.QCoreApplication` to attach to. If no application is provided, it will attempt to find an existing application in memory, or, failing that, create a new application instance.
    timeout    ``0.02``  *Optional.* The maximum time to wait, in seconds, before running :func:`Engine.poll() <pants.engine.Engine.poll>`.
    =========  ========  ============
    """
    global timer
    global _timeout

    Engine.instance()._install_poller(_Qt())

    if app is None:
        app = QCoreApplication.instance()
    if app is None:
        app = QCoreApplication([])

    _timeout = timeout * 1000

    timer = QTimer(app)
    timer.timeout.connect(do_poll)
    timer.start(_timeout)
开发者ID:ixokai,项目名称:pants,代码行数:30,代码来源:qt.py

示例2: close

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
    def close(self):
        """
        Close the channel.
        """
        if self._socket is None:
            return

        Engine.instance().remove_channel(self)
        self._socket_close()
        self._safely_call(self.on_close)
开发者ID:ixokai,项目名称:pants,代码行数:12,代码来源:_channel.py

示例3: process

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
 def process(self):
     """
     Block until the queued requests finish.
     """
     if not self._requests:
         return
     
     self._processing = True
     from pants.engine import Engine
     Engine.instance().start()
开发者ID:chris-statzer,项目名称:ganos,代码行数:12,代码来源:http.py

示例4: callback

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
            def callback(*a,**kw):
                if kw:
                    if a:
                        a = a + (kw, )
                    else:
                        a = kw

                if isinstance(a, tuple) and len(a) == 1:
                    a = a[0]

                data.append(a)
                Engine.instance().stop()
开发者ID:Sureiya,项目名称:pants,代码行数:14,代码来源:dns.py

示例5: _handle_events

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
    def _handle_events(self, events):
        """
        Handle events raised on the channel.

        =========  ============
        Argument   Description
        =========  ============
        events     The events in the form of an integer.
        =========  ============
        """
        if self._socket is None:
            log.warning("Received events for closed %s #%d." %
                    (self.__class__.__name__, self.fileno))
            return

        if events & Engine.READ:
            self._wait_for_read_event = False
            self._handle_read_event()
            if self._socket is None:
                return

        if events & Engine.WRITE:
            self._wait_for_write_event = False
            self._handle_write_event()
            if self._socket is None:
                return

        if events & Engine.ERROR:
            err, errstr = self._get_socket_error()
            if err != 0:
                log.error("Error on %s #%d: %s (%d)" %
                        (self.__class__.__name__, self.fileno, errstr, err))
            self.close()
            return

        if events & Engine.HANGUP:
            log.debug("Hang up on %s #%d." %
                    (self.__class__.__name__, self.fileno))
            self.close()
            return

        events = Engine.ERROR | Engine.HANGUP
        if self._wait_for_read_event:
            events |= Engine.READ
        if self._wait_for_write_event:
            events |= Engine.WRITE
        if events != self._events:
            self._events = events
            Engine.instance().modify_channel(self)
开发者ID:ixokai,项目名称:pants,代码行数:51,代码来源:_channel.py

示例6: _handle_events

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
 def _handle_events(self, events):
     """
     Args:
         events: The events raised on the channel.
     """
     if not self.active():
         log.warning("Received events for closed channel %d." % self.fileno)
         return
     
     # Read event.
     if events & Engine.READ:
         if self._listening:
             self._handle_accept_event()
         elif not self._connected:
             self._handle_connect_event()
         else:
             self._handle_read_event()
         if not self.active():
             return
     
     # Write event.
     if events & Engine.WRITE:
         if not self._connected:
             self._handle_connect_event()
         else:
             self._handle_write_event()
         if not self.active():
             return
     
     # Error event.
     if events & Engine.ERROR:
         self.close_immediately()
         return
     
     # Update events.
     events = Engine.ERROR
     if self.readable():
         events |= Engine.READ
     if self.writable():
         events |= Engine.WRITE
     elif self._closing:
         # Done writing, so close.
         self.close_immediately()
         return
     
     if events != self._events:
         self._events = events
         Engine.instance().modify_channel(self)
开发者ID:chris-statzer,项目名称:ganos,代码行数:50,代码来源:channel.py

示例7: start_event

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
def start_event(owner, delay, event_func, data=None, arg='', *args, **kwargs):
    """
    Schedule a new event to trigger after ``delay`` seconds. Owners may be any
    Python object, but should be an instance of one of:
    :class:`account.Account`, :class:`char.Char`, :class:`exit.Exit`,
    :class:`mudsock.Mudsock`, :class:`obj.Obj`, or :class:`room.Room`.

    If the owner *is* one of those classes, any currently pending events are
    de-scheduled automatically when the owner is destroyed.

    Event functions should take a minimum of three arguments: the event owner,
    ``data``, and ``arg``. This is for compatibility with NakedMud. You may
    provide additional positional and keyword arguments if you wish.

    Returns a callable that de-schedules the event when called.

    ===========  ============
    Argument     Description
    ===========  ============
    owner        The object that owns the event.
    delay        How long, in seconds, to wait before the event function should be called.
    event_func   The function to be called.
    data         *Optional.* Any Python object to be provided to the event function.
    arg          *Optional.* A string to be provided to the event function.
    ===========  ============
    """
    if not owner in __queued__:
        __queued__[owner] = []

    event = Engine.instance().defer(delay, event_func, owner, data, arg, *args, **kwargs)
    __queued__[owner].append(event)
    return event
开发者ID:stendec,项目名称:NakedSun,代码行数:34,代码来源:event.py

示例8: setUp

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
    def setUp(self):
        self.app = Application()
        self.init_app(self.app)

        engine = Engine.instance()
        self.server = HTTPServer(self.app, engine=engine)
        self.server.listen(('127.0.0.1', 4040))
        PantsTestCase.setUp(self, engine)
开发者ID:Sureiya,项目名称:pants,代码行数:10,代码来源:test_web_application.py

示例9: close_immediately

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
 def close_immediately(self):
     """
     Close the socket immediately.
     
     Any pending data will not be sent.
     """
     if not self.active():
         return
     
     if self._write_file:
         self._write_file.close()
         self._write_file = None
         self._write_file_left = None
     
     Engine.instance().remove_channel(self)
     self._socket_close()
     self._update_addr()
     self._safely_call(self.handle_close)
开发者ID:chris-statzer,项目名称:ganos,代码行数:20,代码来源:channel.py

示例10: __init__

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
    def __init__(self, servers=None, engine=None):
        self.servers = servers or list_dns_servers()
        self.engine = engine or Engine.instance()

        # Internal State
        self._messages = {}
        self._cache = {}
        self._queries = {}
        self._tcp = {}
        self._udp = None
        self._last_id = -1
开发者ID:Sureiya,项目名称:pants,代码行数:13,代码来源:dns.py

示例11: __init__

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
 def __init__(self, socket=None):
     """
     Initialises the channel object.
     
     Args:
         socket: A pre-existing socket that this channel should wrap.
             Optional.
     """
     # Socket
     self._socket = socket or self._socket_create()
     self._socket.setblocking(False)
     self.fileno = self._socket.fileno()
     self.remote_addr = (None, None)
     self.local_addr = (None, None)
     
     # Internal state
     self._connected = False
     self._connecting = False
     self._listening = False
     self._closing = False
     
     # Input
     self.read_delimiter = None # String, integer or None.
     self._read_amount = 4096
     self._read_buffer = ""
     
     # Output
     self._write_buffer = ""
     self._secondary_write_buffer = ""
     self._write_file = None
     self._write_file_left = None
     self._write_file_chunk = 65536
     
     # Initialisation
     self._events = Engine.ERROR
     if self.readable():
         self._events |= Engine.READ
     if self.writable():
         self._events |= Engine.WRITE
     Engine.instance().add_channel(self)
开发者ID:chris-statzer,项目名称:ganos,代码行数:42,代码来源:channel.py

示例12: do_poll

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
def do_poll():
    """
    Here, we run the Pants event loop. Then, we set the timer interval, either
    to the provided timeout, or for how long it would take to reach the
    earliest deferred event.
    """
    engine = Engine.instance()

    engine.poll(0)

    if engine._deferreds:
        timer.setInterval(min(1000 * (engine._deferreds[0].end - engine.time), _timeout))
    else:
        timer.setInterval(_timeout * 1000)
开发者ID:ixokai,项目名称:pants,代码行数:16,代码来源:qt.py

示例13: __init__

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
    def __init__(self, **kwargs):
        # Keyword arguments
        sock_family = kwargs.get("family", socket.AF_INET)
        sock_type = kwargs.get("type", socket.SOCK_STREAM)
        sock = kwargs.get("socket", None)
        if sock is None:
            sock = socket.socket(sock_family, sock_type)

        # Socket
        self.fileno = None
        self._socket = None
        self._socket_set(sock)

        # Socket state
        self._wait_for_read_event = True
        self._wait_for_write_event = True

        # I/O attributes
        self._recv_amount = 4096

        # Events
        self._events = Engine.ALL_EVENTS
        Engine.instance().add_channel(self)
开发者ID:ixokai,项目名称:pants,代码行数:25,代码来源:_channel.py

示例14: doer

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
        def doer(*a, **kw):
            if Engine.instance()._running:
                raise RuntimeError("synchronous calls cannot be made while Pants is already running.")

            data = []

            def callback(*a,**kw):
                if kw:
                    if a:
                        a = a + (kw, )
                    else:
                        a = kw

                if isinstance(a, tuple) and len(a) == 1:
                    a = a[0]

                data.append(a)
                Engine.instance().stop()

            kw['callback'] = callback
            func(*a, **kw)
            Engine.instance().start()
            return data[0]
开发者ID:Sureiya,项目名称:pants,代码行数:25,代码来源:dns.py

示例15: install

# 需要导入模块: from pants.engine import Engine [as 别名]
# 或者: from pants.engine.Engine import instance [as 别名]
def install(app=None, timeout=0.02):
    """
    Sets up the timer. This isn't necessary if you're going to be calling
    poll yourself. (And, if you ARE going to be calling poll yourself: why?)

    Args:
        app: The QApplication to attach to. If None, it will attempt to find
            the app or, failing that, it will create a new QCoreApplication
            instance.
        timeout: The length of time, in seconds, to wait between each call to
            the engine's poll function.
    """
    global timer
    
    Engine.instance()._install_poller(_Qt())
    
    if app is None:
        app = QCoreApplication.instance()
    if app is None:
        app = QCoreApplication([])

    timer = QTimer(app)
    timer.timeout.connect(functools.partial(Engine.instance().poll, 0))
    timer.start(timeout * 1000)
开发者ID:chris-statzer,项目名称:ganos,代码行数:26,代码来源:qt.py


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