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


Python Manager.flush方法代码示例

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


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

示例1: test

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
def test():
    m = Manager() + A() + B() + C()

    while m:
        m.flush()

    # Rely on Event.channels
    x = m.fire(foo())
    m.flush()
    assert x.value == "Foo"

    # Explicitly specify the channel
    x = m.fire(foo(), "b")
    m.flush()
    assert x.value == "Hello World!"

    # Explicitly specify a set of channels
    x = m.fire(foo(), "a", "b")
    m.flush()
    assert x.value == ["Foo", "Hello World!"]

    # Rely on self.channel
    x = m.fire(foo(), "c")
    m.flush()
    m.flush()
    assert x.value == "Bar"
开发者ID:treemo,项目名称:circuits,代码行数:28,代码来源:test_channel_selection.py

示例2: test_complex

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
def test_complex():
    m = Manager()

    a = A()
    b = B()

    a.register(m)
    b.register(a)

    assert a in m
    assert a.root == m
    assert a.parent == m
    assert b in a
    assert b.root == m
    assert b.parent == a

    a.unregister()
    while len(m):
        m.flush()

    assert b.informed
    assert a not in m
    assert a.root == a
    assert a.parent == a
    assert b in a
    assert b.root == a
    assert b.parent == a
开发者ID:AdricEpic,项目名称:circuits,代码行数:29,代码来源:test_component_setup.py

示例3: test_basic

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
def test_basic():
    m = Manager()

    app = App()
    app.register(m)

    assert app.test in app._handlers.get("test", set())

    app.unregister()
    while len(m):
        m.flush()

    assert not m._handlers
开发者ID:AdricEpic,项目名称:circuits,代码行数:15,代码来源:test_component_setup.py

示例4: __init__

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
class ComponentRunner:
    instance = None
    
    def __init__(self):
        # instanciated from the c++ side, as modulemanager there
        #assert self.instance is None
        ComponentRunner.instance = self #is used as a singleton now. is this needed anywhere actually? XXX
        
        self.mouseinfo = MouseInfo(0,0,0,0)
        #m.start() #instead we tick() & flush() in update
        
        self.firstrun = True
        r.restart = False
        self.start()
        r.manager = self

    def start(self):
        # Create a new circuits Manager
        #ignevents = [Update, MouseMove]
        ignchannames = ['update', 'started', 'on_mousemove', 'on_mousedrag', 'on_keydown', 'on_input', 'on_mouseclick', 'on_entityupdated', 'on_exit', 'on_keyup', 'on_login', 'on_inboundnetwork', 'on_genericmessage', 'on_scene', 'on_entity_visuals_modified', 'on_logout', 'on_worldstreamready', 'on_sceneadded']
        ignchannels = [('*', n) for n in ignchannames]
        
        # Note: instantiating Manager with debugger causes severe lag when running as a true windowed app (no console), so instantiate without debugger
        # Fix attempt: give the circuits Debugger a logger which uses Naali logging system, instead of the default which writes to sys.stderr
        # Todo: if the default stdout is hidden, the py stdout should be changed
        # to something that shows e.g. in console, so prints from scripts show
        # (people commonly use those for debugging so they should show somewhere)
        d = Debugger(IgnoreChannels = ignchannels, logger=NaaliLogger()) #IgnoreEvents = ignored)
        self.m = Manager() + d
        #self.m = Manager()

        #or __all__ in pymodules __init__ ? (i.e. import pymodules would do that)
        if self.firstrun:
            import autoload
            self.firstrun = False
        else: #reload may cause something strange sometimes, so better not do it always in production use, is just a dev tool.
            #print "reloading autoload"
            import autoload
            autoload = reload(autoload)            
        #print "Autoload module:", autoload
        autoload.load(self.m)

        self.m.push(Started(self.m, None)) #webserver requires this now, temporarily XXX
                    
    def run(self, deltatime=0.1):
        #print "."
        self.send_event(Update(deltatime), "update") #so that all components are updated immediately once for this frame
        #XXX should this be using the __tick__ mechanism of circuits, and how?
        m = self.m
        m.tick()

    def send_event(self, event, channel):
        """simulate sync sending of events using the async lib.
        needed to be able to return the info of whether the event is to be
        send to more handlers on the c++ side in the Naali event system"""
        m = self.m
        ret = m.push(event, channel)
        while m: m.flush() #circuits components evaluate to false when have no pending events left
        if not ret.errors:
            #print "EVENT:", event, ret.value
            return True in ret #circuits return values implement __contains__ for this use case
        else:
            #did the debugger already show the traceback?
            return False
        
    def RexNetMsgChatFromSimulator(self, frm, message):
        self.send_event(Chat(frm, message), "on_chat")
        
    def INPUT_EVENT(self, evid):
        """Note: the PygameDriver for circuits has a different design:
        there the event data is Key, and the channel either "keydown" or "keyup",
        and mouse and clicks are different events and channels.
        Here we have no way to differentiate presses/releases,
        'cause the c++ internals don't do that apart from the constant name.
        """
        #print "circuits_manager ComponentRunner got input event:", evid       
        return self.send_event(Input(evid), "on_input")
        
    def KEY_INPUT_EVENT(self, evid, keycode, keymod):
        """Handles key inputs, creates a Circuits Key event with the data provided
        WIP, since on_keydown call doesn't work for now, resorted in using Input(keycode)
        instead, works similarly but still not the way it should
        """
        
        #print "CircuitManager received KEY_INPUT (event:", evid, "key:", keycode, "mods:", keymod, ")"
        #print r.KeyPressed, r.KeyReleased
        if evid == 39: #r.KeyPressed:
            return self.send_event(Key(keycode, keymod), "on_keydown")
        elif evid == 40: #r.KeyReleased:
            return self.send_event(Key(keycode, keymod), "on_keyup")
            
    def MOUSE_DRAG_INPUT_EVENT(self, event, x_abs, y_abs, x_rel, y_rel):
        self.mouseinfo.setInfo(x_abs, y_abs, x_rel, y_rel)
        #print "CircuitsManager got mouse movement", self.mouseinfo, self.mouseinfo.x, self.mouseinfo.y
        return self.send_event(MouseMove(event, self.mouseinfo), "on_mousedrag")
        
    def MOUSE_INPUT_EVENT(self, event, x_abs, y_abs, x_rel, y_rel):
        #print "CircuitsManager got a mouse click", mb_click, x_abs, y_abs, x_rel, y_rel
        #print "CircuitsManager", event
        self.mouseinfo.setInfo(x_abs, y_abs, x_rel, y_rel)
#.........这里部分代码省略.........
开发者ID:Ilikia,项目名称:naali,代码行数:103,代码来源:circuits_manager.py

示例5: main

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
def main():
    opts, args = parse_options()

    if opts.speed and psyco:
        psyco.full()

    manager = Manager()

    monitor = Monitor(opts)
    manager += monitor

    state = State(opts)
    manager += state

    if opts.debug:
        manager += Debugger()

    if opts.listen or args:
        nodes = []
        if args:
            for node in args:
                if ":" in node:
                    host, port = node.split(":")
                    port = int(port)
                else:
                    host = node
                    port = 8000
                nodes.append((host, port))

        if opts.bind is not None:
            if ":" in opts.bind:
                address, port = opts.bind.split(":")
                port = int(port)
            else:
                address, port = opts.bind, 8000

        bridge = Bridge(bind=(address, port), nodes=nodes)
        manager += bridge
        bridge.start()

    if opts.mode.lower() == "speed":
        if opts.verbose:
            print "Setting up Speed Test..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += SpeedTest(opts, channel=c)
        else:
            manager += SpeedTest(opts)
        monitor.sTime = time.time()
    elif opts.mode.lower() == "latency":
        if opts.verbose:
            print "Setting up Latency Test..."
        manager += LatencyTest(opts)
        monitor.sTime = time.time()
    elif opts.listen:
        if opts.verbose:
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Receiver(opts, channel=c)
        else:
            manager += Receiver(opts)
    elif args:
        if opts.verbose:
            print "Setting up Sender..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(opts, channel=c)
        else:
            manager += Sender(opts)
    else:
        if opts.verbose:
            print "Setting up Sender..."
            print "Setting up Receiver..."
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager += Sender(channel=c)
                manager += Receiver(opts, channel=c)
        else:
            manager += Sender(opts)
            manager += Receiver(opts)
        monitor.sTime = time.time()

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile("bench.prof")
            profiler.start()

    if not opts.wait:
        if opts.concurrency > 1:
            for c in xrange(int(opts.concurrency)):
                manager.push(Hello("hello"), "hello", c)
        else:
            manager.push(Hello("hello"), "hello")

    while not state.done:
        try:
            manager.flush()

            for i in xrange(opts.fill):
#.........这里部分代码省略.........
开发者ID:Belsepubi,项目名称:naali,代码行数:103,代码来源:bench.py

示例6: Input

# 需要导入模块: from circuits import Manager [as 别名]
# 或者: from circuits.Manager import flush [as 别名]
        self.commands.append("stop")

if __name__ == '__main__':
    from circuits import Event, Manager, Debugger
    class Input(Event): pass

    m = Manager()
    c = TestThread()
    m += c + Debugger()

    now = time.time()
    interval = 0.5
    prev_time = now

    try:
        while 1:
            now = time.time()
            if prev_time + interval < now:
                m.push(Input(1), "on_input")
                prev_time = now
            while m:
                m.flush()

    except KeyboardInterrupt:
        print "stopping"
        m.stop()
    
        while m:
            m.flush()
        c.join()
开发者ID:A-K,项目名称:naali,代码行数:32,代码来源:thread_test.py


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