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


Python protocol.invokeLater函数代码示例

本文整理汇总了Python中tcf.protocol.invokeLater函数的典型用法代码示例。如果您正苦于以下问题:Python invokeLater函数的具体用法?Python invokeLater怎么用?Python invokeLater使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: testStackTrace

def testStackTrace(c):
    from tcf.services import stacktrace

    def stackTest(ctx_id):
        stack = c.getRemoteService(stacktrace.NAME)

        class DoneGetChildren(stacktrace.DoneGetChildren):
            def doneGetChildren(self, token, error, ctx_ids):
                if error:
                    protocol.log("Error from StackTrace.getChildren", error)
                    return

                class DoneGetContext(stacktrace.DoneGetContext):
                    def doneGetContext(self, token, error, ctxs):
                        if error:
                            protocol.log(
                                "Error from StackTrace.getContext", error)
                            return
                        if ctxs:
                            for ctx in ctxs:
                                print ctx
                stack.getContext(ctx_ids, DoneGetContext())
        stack.getChildren(ctx_id, DoneGetChildren())
    for ctx_id in _suspended:
        protocol.invokeLater(stackTest, ctx_id)
开发者ID:deviprasad742,项目名称:tcf,代码行数:25,代码来源:BasicTests.py

示例2: testSymbols

def testSymbols(c):
    from tcf.services import symbols

    def symTest(ctx_id):
        syms = c.getRemoteService(symbols.NAME)

        class DoneList(symbols.DoneList):
            def doneList(self, token, error, ctx_ids):
                if error:
                    protocol.log("Error from Symbols.list", error)
                    return

                class DoneGetContext(symbols.DoneGetContext):
                    def doneGetContext(self, token, error, ctx):
                        if error:
                            protocol.log(
                                "Error from Symbols.getContext", error)
                            return
                        print ctx
                if ctx_ids:
                    for ctx_id in ctx_ids:
                        syms.getContext(ctx_id, DoneGetContext())
        syms.list(ctx_id, DoneList())
    for ctx_id in _suspended:
        protocol.invokeLater(symTest, ctx_id)
开发者ID:deviprasad742,项目名称:tcf,代码行数:25,代码来源:BasicTests.py

示例3: testMemory

def testMemory(c):
    lock = threading.Condition()
    from tcf.services import memory
    def getContexts():
        mem = c.getRemoteService(memory.NAME)
        pending = []
        class DoneGetContext(memory.DoneGetContext):
            def doneGetContext(self, token, error, context):
                pending.remove(token)
                if error:
                    protocol.log("Error from Memory.getContext", error)
                else:
                    print context
                if len(pending) == 0:
                    with lock:
                        lock.notify()
        class DoneGetChildren(memory.DoneGetChildren):
            def doneGetChildren(self, token, error, context_ids):
                pending.remove(token)
                if error:
                    protocol.log("Error from Memory.GetChildren", error)
                else:
                    for c in context_ids:
                        _memory.append(c)
                        pending.append(mem.getContext(c, DoneGetContext()))
                        pending.append(mem.getChildren(c, self))
                if len(pending) == 0:
                    with lock:
                        lock.notify()
        pending.append(mem.getChildren(None, DoneGetChildren()))
    with lock:
        protocol.invokeLater(getContexts)
        lock.wait(5)
开发者ID:eswartz,项目名称:emul,代码行数:33,代码来源:BasicTests.py

示例4: testDataCache

def testDataCache(c):
    from tcf.util import cache
    from tcf.services import runcontrol
    if not runcontrol.NAME in _services:
        return

    class ContextsCache(cache.DataCache):
        def startDataRetrieval(self):
            rc = self._channel.getRemoteService(runcontrol.NAME)
            if not rc:
                self.set(None, Exception("No RunControl service"), None)
                return
            cache = self
            pending = []
            contexts = []

            class DoneGetChildren(runcontrol.DoneGetChildren):
                def doneGetChildren(self, token, error, context_ids):
                    pending.remove(token)
                    if error:
                        protocol.log(
                            "Error from RunControl.GetChildren", error)
                    else:
                        for c in context_ids:
                            contexts.append(c)
                            pending.append(rc.getChildren(c, self))
                    if len(pending) == 0:
                        cache.set(None, None, contexts)
            pending.append(rc.getChildren(None, DoneGetChildren()))
    contextsCache = ContextsCache(c)

    def done():
        print "ContextsCache is valid:", contextsCache.getData()
    protocol.invokeLater(contextsCache.validate, done)
开发者ID:deviprasad742,项目名称:tcf,代码行数:34,代码来源:BasicTests.py

示例5: getChildren

def getChildren(service, contextID=None):
    """Get a TCF context IDs from a given service.

    As many TCF services have a **getChildren()** command, this function is
    intended to implement a service-independant **getChildren()** command.

    :param service: The TCF service to get context list from.
    :param contextID: parent ID of the context list to get from *service*.

    :returns: A tuple of context IDs. Tuple may be empty on error, or if
              *contextID* does not have children.
    """
    def callGetChildren(service, condition, val):
        """Asynchronous request to get context children.

        :param service: The TCF service proxy to send request to.
        :param condition: A threading.Condition the caller is pending on.
                          Caller is released from waiting through a
                          Condition.notify() call.
        :param val: A TcfValue handling the request returned value.

        :returns: **None**, always.
        """
        class DoneGetChildren(object):
            """Client callback class for <service>.getChildren() command."""
            def doneGetChildren(self, token, error, ids):
                """Called when context list retrieval is done.

                :param token: pending command handle.
                :param error: error description if operation failed, **None**
                              if succeeded.
                :param context_ids: array of available context IDs.
                """
                if error:
                    protocol.log("Error from " + service.getName() + \
                                 ".getContext()", error)
                else:
                    val.setValue(ids)
                with condition:
                    condition.notify()

        # start the process itself

        service.getChildren(contextID, DoneGetChildren())

    # create a condition to wait on, and a value to get the children ids

    lock = threading.Condition()
    value = TcfValue()

    with lock:
        # TCF requests must be called by the dispatch thread, wait for a
        # maximum of 10 seconds
        protocol.invokeLater(callGetChildren, service=service, condition=lock,
                             val=value)
        lock.wait(10)

    # Return the retrieved children IDs, or an empty tuple

    return (tuple(value.getValue() or []))
开发者ID:ppalaga,项目名称:tcf,代码行数:60,代码来源:ProcessStart.py

示例6: testRegisters

def testRegisters(c):
    if not _suspended: return
    from tcf.services import registers
    lock = threading.Condition()
    def regTest(ctx_id):
        regs = c.getRemoteService(registers.NAME)
        pending = []
        def onDone():
            with lock: lock.notify()
        class DoneGetChildren(registers.DoneGetChildren):
            def doneGetChildren(self, token, error, ctx_ids):
                pending.remove(token)
                if error:
                    protocol.log("Error from Registers.getChildren", error)
                if not pending:
                    onDone()
                class DoneGetContext(registers.DoneGetContext):
                    def doneGetContext(self, token, error, ctx):
                        pending.remove(token)
                        if error:
                            protocol.log("Error from Registers.getContext", error)
                        else:
                            print ctx
                            if ctx.isReadable() and not ctx.isReadOnce() and ctx.getSize() >= 2:
                                locs = []
                                locs.append(registers.Location(ctx.getID(), 0, 1))
                                locs.append(registers.Location(ctx.getID(), 1, 1))
                                class DoneGetM(registers.DoneGet):
                                    def doneGet(self, token, error, value):
                                        pending.remove(token)
                                        if error:
                                            protocol.log("Error from Registers.getm", error)
                                        else:
                                            print "getm", ctx.getID(), map(ord, value)
                                        if not pending:
                                            onDone()
                                pending.append(regs.getm(locs, DoneGetM()))
                            if ctx.isWriteable() and not ctx.isWriteOnce() and ctx.getSize() >= 2:
                                locs = []
                                locs.append(registers.Location(ctx.getID(), 0, 1))
                                locs.append(registers.Location(ctx.getID(), 1, 1))
                                class DoneSetM(registers.DoneSet):
                                    def doneGet(self, token, error):
                                        pending.remove(token)
                                        if error:
                                            protocol.log("Error from Registers.setm", error)
                                        if not pending:
                                            onDone()
                                pending.append(regs.setm(locs, (255, 255), DoneSetM()))
                        if not pending:
                            onDone()
                if ctx_ids:
                    for ctx_id in ctx_ids:
                        pending.append(regs.getContext(ctx_id, DoneGetContext()))
        pending.append(regs.getChildren(ctx_id, DoneGetChildren()))
    with lock:
        for ctx_id in _suspended:
            protocol.invokeLater(regTest, ctx_id)
        lock.wait(5)
开发者ID:eswartz,项目名称:emul,代码行数:59,代码来源:BasicTests.py

示例7: testBreakpoints

def testBreakpoints(c):
    from tcf.services import breakpoints  # @UnresolvedImport

    def testBPQuery():
        bps = c.getRemoteService(breakpoints.NAME)

        def doneGetIDs(token, error, ids):
            if error:
                protocol.log("Error from Breakpoints.getIDs", error)
                return
            print("Breakpoints : " + str(ids))

            def doneGetProperties(token, error, props):
                if error:
                    protocol.log("Error from Breakpoints.getProperties", error)
                    return
                print("Breakpoint Properties: " + str(props))

            def doneGetStatus(token, error, props):
                if error:
                    protocol.log("Error from Breakpoints.getStatus", error)
                    return
                print("Breakpoint Status: " + str(props))
            for bpid in ids:
                bps.getProperties(bpid, doneGetProperties)
                bps.getStatus(bpid, doneGetStatus)
        bps.getIDs(doneGetIDs)
    protocol.invokeLater(testBPQuery)

    def testBPSet():
        bpsvc = c.getRemoteService(breakpoints.NAME)

        class BPListener(breakpoints.BreakpointsListener):
            def breakpointStatusChanged(self, bpid, status):
                print("breakpointStatusChanged " + str(bpid) + " " +
                      str(status))

            def contextAdded(self, bps):
                print("breakpointAdded " + str(bps))
                bpsvc.removeListener(self)

            def contextChanged(self, bps):
                print("breakpointChanged " + str(bps))

            def contextRemoved(self, ids):
                print("breakpointRemoved " + str(ids))
        bpsvc.addListener(BPListener())

        def doneSet(token, error):
            if error:
                protocol.log("Error from Breakpoints.set", error)
                return
        bp = {
            breakpoints.PROP_ID: "python:1",
            breakpoints.PROP_ENABLED: True,
            breakpoints.PROP_LOCATION: "sysClkRateGet"
        }
        bpsvc.set([bp], doneSet)
    protocol.invokeLater(testBPSet)
开发者ID:eclipse,项目名称:tcf,代码行数:59,代码来源:BasicTests.py

示例8: cancel

 def cancel(self):
     if not protocol.isDispatchThread():
         protocol.invokeLater(self.cancel)
         return
     with self._lock:
         for cmd in self._pending.values():
             cmd.token.cancel()
         del self._queue[:]
开发者ID:eswartz,项目名称:emul,代码行数:8,代码来源:sync.py

示例9: subscribe

def subscribe(svc, streamType, listener):
    """Subscribe to a streams channel.

    :param svc: The TCF streams proxy to subscribe against.
    :param streamType: Type of the stream to register against. For now,
                       I only know of 'Terminals', 'Processes' and
                       'ProcessesV1' types.
    :param listener: The listener to subscribe to *svc*.
    :type listener: tcf.services.streams.StreamsListener

    :returns: **None**, always.
    """
    def callSubscribe(service, streamType, listener, condition):
        """Asynchronous request to subscribe a listener to streams service.

        :param service: The streams service to subscribe listener against.
        :param streamType: Type of the stream to register against. For now,
                           I only know of 'Terminals', 'Processes' and
                           'ProcessesV1' types.
        :param listener: The listener to subscribe to *service*.
        :type listener: tcf.services.streams.StreamsListener
        :param condition: A threading.Condition the caller is pending on.
                          Caller is released from waiting through a
                          Condition.notify() call.

        :returns: **None**, always.
        """
        class DoneSubscribe(streams.DoneSubscribe):
            """Call back interface for StreamsService.subscribe() command."""
            def doneSubscribe(self, token, error):
                """Called when stream subscription is done.

                :param token: pending command handle
                :param error: error description if operation failed, **None**
                              if succeeded.
                """
                if error:
                    protocol.log("Error from streams.subscribe()", error)
                with condition:
                    condition.notify()

        # start the process itself

        service.subscribe(streamType, listener, DoneSubscribe())

    # create a condition to wait on

    lock = threading.Condition()

    with lock:
        # TCF requests must be called by the dispatche thread, wait for a
        # maximum of 10 seconds
        protocol.invokeLater(callSubscribe, service=svc, streamType=streamType,
                             listener=listener, condition=lock)
        lock.wait(10)
开发者ID:ppalaga,项目名称:tcf,代码行数:55,代码来源:ProcessStart.py

示例10: _close

    def _close(self, error):
        assert self.state != STATE_CLOSED
        self.state = STATE_CLOSED
        # Closing channel underlying streams can block for a long time,
        # so it needs to be done by a background thread.
        thread = threading.Thread(target=self.stop, name="TCF Channel Cleanup")
        thread.daemon = True
        thread.start()
        if error and isinstance(self.remote_peer, peer.AbstractPeer):
            self.remote_peer.onChannelTerminated()
        if self.registered_with_trasport:
            self.registered_with_trasport = False
            transport.channelClosed(self, error)
        if self.proxy:
            try:
                self.proxy.onChannelClosed(error)
            except Exception as x:
                protocol.log("Exception in channel listener", x)
        channel = self
        class Runnable(object):
            def __call__(self):
                if channel.out_tokens:
                    x = None
                    if isinstance(error, Exception): x = error
                    elif error: x = Exception(error)
                    else: x = IOError("Channel is closed")
                    for msg in channel.out_tokens.values():
                        try:
                            s = str(msg)
                            if len(s) > 72: s = s[:72] + "...]"
                            y = IOError("Command " + s + " aborted")
#                            y.initCause(x)
                            msg.token.getListener().terminated(msg.token, y)
                        except Exception as e:
                            protocol.log("Exception in command listener", e)
                    channel.out_tokens.clear()
                if channel.channel_listeners:
                    for l in channel.channel_listeners:
                        if not l: break
                        try:
                            l.onChannelClosed(error)
                        except Exception as x:
                            protocol.log("Exception in channel listener", x)
                elif error:
                    protocol.log("TCF channel terminated", error)
                if channel.trace_listeners:
                    for l in channel.trace_listeners:
                        try:
                            l.onChannelClosed(error)
                        except Exception as x:
                            protocol.log("Exception in channel listener", x)
        protocol.invokeLater(Runnable())
开发者ID:eswartz,项目名称:emul,代码行数:52,代码来源:AbstractChannel.py

示例11: testProcesses

def testProcesses(c):
    from tcf.services import processes, processes_v1
    def processTest():
        proc = c.getRemoteService(processes_v1.NAME) or c.getRemoteService(processes.NAME)
        if not proc:
            return
        class DoneGetChildren(processes.DoneGetChildren):
            def doneGetChildren(self, token, error, context_ids):
                if error:
                    protocol.log("Error from Processes.GetChildren", error)
                else:
                    print "Processes:", context_ids
        proc.getChildren(None, False, DoneGetChildren())
    protocol.invokeLater(processTest)
开发者ID:eswartz,项目名称:emul,代码行数:14,代码来源:BasicTests.py

示例12: testSysMonitor

def testSysMonitor(c):
    cmd = sync.CommandControl(c)
    try:
        sm = cmd.SysMonitor
    except AttributeError:
        # no SysMonotor service
        return
    lock = threading.Condition()
    from tcf.services import sysmonitor
    processes = []

    def getProcesses():
        sm = c.getRemoteService(sysmonitor.NAME)
        pending = []

        class DoneGetChildren(sysmonitor.DoneGetChildren):
            def doneGetChildren(self, token, error, context_ids):
                pending.remove(token)
                if error:
                    protocol.log("Error from SysMonitor.getChildren", error)
                else:
                    class DoneGetContext(sysmonitor.DoneGetContext):
                        def doneGetContext(self, token, error, context):
                            pending.remove(token)
                            if error:
                                protocol.log(
                                    "Error from SysMonitor.getContext", error)
                            else:
                                processes.append(context)
                            if not pending:
                                with lock:
                                    lock.notify()
                    for ctx_id in context_ids:
                        pending.append(
                            sm.getContext(ctx_id, DoneGetContext()))
                if not pending:
                    with lock:
                        lock.notify()
        pending.append(sm.getChildren(None, DoneGetChildren()))
    with lock:
        protocol.invokeLater(getProcesses)
        lock.wait(5)
    print "%d processes found:" % len(processes)
    for p in processes:
        print p
        cmdl = sm.getCommandLine(p.getID()).get()
        if cmdl:
            print "Command line: ", cmdl
        envp = sm.getEnvironment(p.getID()).get()
        print "Environment: ", envp
开发者ID:deviprasad742,项目名称:tcf,代码行数:50,代码来源:BasicTests.py

示例13: invoke

 def invoke(self, service, command, *args, **kwargs):
     cmd = None
     if not protocol.isDispatchThread():
         if not kwargs.get("async"):
             cmd = protocol.invokeAndWait(self._invoke, service, command, *args, **kwargs)
             if cmd and self._interactive:
                 return cmd.getE()
         else:
             with self._lock:
                 self._queue.append((service, command, args, kwargs))
                 if len(self._queue) == 1:
                     protocol.invokeLater(self._processQueue)
             return
     return cmd
开发者ID:eswartz,项目名称:emul,代码行数:14,代码来源:sync.py

示例14: __init__

 def __init__(self, channel, service, command, args):
     if isinstance(service, services.Service):
         service = service.getName()
     self.service = service
     self.command = command
     self.args = args
     t = None
     try:
         # TODO zero_copy
         #zero_copy = channel.isZeroCopySupported()
         t = channel.sendCommand(service, command, toJSONSequence(args), self)
     except Exception as y:
         t = Token()
         protocol.invokeLater(self._error, y)
     self.token = t
开发者ID:eswartz,项目名称:emul,代码行数:15,代码来源:Command.py

示例15: resume

def resume(context):
    """Resume a runcontrol context.

    The given *context* should be a RunControlContext, so that its resume()
    method may be called.

    :param context: A runcontrol context to resume.
    :type process: RunControlContext

    :returns: **None**, always.
    """
    def callResume(context, condition):
        """Asynchronous request to resume runcontrol context.

        :param context: The TCF RunControlContext to resume.
        :param condition: A threading.Condition the caller is pending on.
                          Caller is released from waiting through a
                          Condition.notify() call.

        :returns: **None**, always.
        """
        class DoneResume(runcontrol.DoneCommand):
            """Client call back interface for RunControlContext.resume()."""
            def doneCommand(self, token, error):
                """Called when run control command execution is complete.

                :param token: pending command handle.
                :param error: command execution error or **None**.
                """
                if error:
                    protocol.log("Error from RunContext.resume", error)
                with condition:
                    condition.notify()

        # Resume context with RM_RESUME mode, 1 time. No resume properties.

        context.resume(runcontrol.RM_RESUME, 1, {}, DoneResume())

    # create a condition to wait on

    lock = threading.Condition()

    with lock:
        # TCF requests must be called by the dispatch thread, wait for a
        # maximum of 10 seconds

        protocol.invokeLater(callResume, context=context, condition=lock)
        lock.wait(10)
开发者ID:ppalaga,项目名称:tcf,代码行数:48,代码来源:ProcessStart.py


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