Example #1
0
 def testLateWait(self):
     t = GetTask(("foo", "bar"), max = 0.001)
     self.assertFalse(t.done())
     main.sleep(0.002)
     self.assertTrue(t.done())
     t.wait()
     self.assertTrue(t.done())
     self.assertEqual(t.result(), ("foo", "bar"))
Example #2
0
        def func():
            me = stackless.getcurrent()

            def killer():
                me.kill()

            stackless.tasklet(killer)()
            return main.sleep(0.1)
Example #3
0
 def f():
     main.sleep(t)
     raise exception
Example #4
0
 def f(*args):
     #t0 = time.clock()
     #print "sleeping for ", t
     main.sleep(t)
     #print "slept for", time.clock()-t0, "wanted", t
     return args
Example #5
0
 def sleep(self, d):
     main.sleep(d)
Example #6
0
 def func():
     return main.sleep(0.1)
Example #7
0
def Run():
    global bootstrapState

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s;%(name)s;%(levelname)s;%(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')

    logging.getLogger().name = "default"
    logging.getLogger("namespace").setLevel(logging.INFO)
    logging.getLogger("reloader").setLevel(logging.INFO)

    stackless.getcurrent().block_trap = True

    iniFilename = os.path.join(dirPath, "config.ini")
    if not os.path.exists(iniFilename):
        print "Please copy 'config.ini.base' to 'config.ini' and modify it appropriately."
        sys.exit(0)

    # Monkey-patch in the stackless-compatible sockets.
    import stacklesssocket
    import uthread2
    import stacklesslib.main as stacklesslibmain
    stacklesssocket._schedule_func = lambda delay=0: stacklesslibmain.sleep(
        delay)
    stacklesssocket._sleep_func = stacklesslibmain.sleep
    stacklesssocket.install()

    # Install the global event handler.
    import __builtin__
    from events import EventHandler
    __builtin__.events = EventHandler()

    # Add the "livecoding" contrib directory to the path.
    livecodingDirPath = os.path.join(dirPath, "contrib", "livecoding")
    if os.path.exists(livecodingDirPath):
        sys.path.append(livecodingDirPath)

    # Register the mudlib and game script directories with the livecoding
    # module.  This will compile and execute them all.
    import reloader
    #gamePath = os.path.join("games", "room - simple")
    gamePath = os.path.join("games", "roguelike")
    gameScriptPath = os.path.join(dirPath, gamePath)
    mudlibScriptPath = os.path.join(dirPath, "mudlib")

    cr = reloader.CodeReloader()
    # Register for code reloading updates of managed classes.
    # Broadcast an event when we receive an update.
    cr.SetClassCreationCallback(OnClassCreation)
    cr.SetClassUpdateCallback(OnClassUpdate)
    cr.SetValidateScriptCallback(OnScriptValidation)
    cr.AddDirectory("mudlib", mudlibScriptPath)
    cr.AddDirectory("game", gameScriptPath)

    import imp
    __builtin__.sorrows = imp.new_module('sorrows')

    from mudlib.services import ServiceService
    svcSvc = ServiceService()
    svcSvc.gameScriptPath = gamePath
    svcSvc.gameDataPath = os.path.join(gamePath, "data")
    svcSvc.Register()
    svcSvc.Start()
    del svcSvc

    stackless.getcurrent().block_trap = False
    bootstrapState = STATE_RUNNING

    manualShutdown = False
    try:
        stacklesslibmain.mainloop.run()
    except KeyboardInterrupt:
        print
        print '** EXITING: Server manually stopping.'
        print

        if stackless.runcount > 1:
            print "Scheduled tasklets:", stackless.runcount
            uthread2.PrintTaskletChain(stackless.current)
            print

        if False:
            for entry in stacklesslibmain.event_queue.queue_a:
                print "Sleeping tasklets:"
                uthread2.PrintTaskletChain(uthread.yieldChannel.queue)
                print

            for timestamp, channel in uthread.sleepingTasklets:
                if channel.queue:
                    print "Sleep channel (%d) tasklets:" % id(channel)
                    uthread2.PrintTaskletChain(channel.queue)
                    print

        manualShutdown = True
    finally:
        cr.EndMonitoring()

    bootstrapState = STATE_SHUTDOWN

    if manualShutdown:

        class HelperClass:
            def ShutdownComplete(self):
                stacklesslibmain.mainloop.stop()
                managerTasklet.kill()

        helper = HelperClass()
        events.ShutdownComplete.Register(helper.ShutdownComplete)

        stackless.tasklet(sorrows.services.Stop)()
        # We have most likely killed the stacklesssocket tasklet.
        managerTasklet = stacklesssocket.StartManager()
        stacklesslibmain.mainloop.run()

    logging.info("Shutdown complete")
Example #8
0
def Run():
    global bootstrapState

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s;%(name)s;%(levelname)s;%(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')

    logging.getLogger().name = "default"
    logging.getLogger("namespace").setLevel(logging.INFO)
    logging.getLogger("reloader").setLevel(logging.INFO)

    stackless.getcurrent().block_trap = True

    iniFilename = os.path.join(dirPath, "config.ini")
    if not os.path.exists(iniFilename):
        print "Please copy 'config.ini.base' to 'config.ini' and modify it appropriately."
        sys.exit(0)

    # Monkey-patch in the stackless-compatible sockets.
    import stacklesssocket
    import uthread2
    import stacklesslib.main as stacklesslibmain
    stacklesssocket._schedule_func = lambda delay=0: stacklesslibmain.sleep(delay)
    stacklesssocket._sleep_func = stacklesslibmain.sleep
    stacklesssocket.install()

    # Install the global event handler.
    import __builtin__
    from events import EventHandler
    __builtin__.events = EventHandler()

    # Add the "livecoding" contrib directory to the path.
    livecodingDirPath = os.path.join(dirPath, "contrib", "livecoding")
    if os.path.exists(livecodingDirPath):
        sys.path.append(livecodingDirPath)

    # Register the mudlib and game script directories with the livecoding
    # module.  This will compile and execute them all.
    import reloader
    #gamePath = os.path.join("games", "room - simple")
    gamePath = os.path.join("games", "roguelike")
    gameScriptPath = os.path.join(dirPath, gamePath)
    mudlibScriptPath = os.path.join(dirPath, "mudlib")

    cr = reloader.CodeReloader()
    # Register for code reloading updates of managed classes.
    # Broadcast an event when we receive an update.
    cr.SetClassCreationCallback(OnClassCreation)
    cr.SetClassUpdateCallback(OnClassUpdate)
    cr.SetValidateScriptCallback(OnScriptValidation)
    cr.AddDirectory("mudlib", mudlibScriptPath)
    cr.AddDirectory("game", gameScriptPath)

    import imp
    __builtin__.sorrows = imp.new_module('sorrows')

    from mudlib.services import ServiceService
    svcSvc = ServiceService()
    svcSvc.gameScriptPath = gamePath
    svcSvc.gameDataPath = os.path.join(gamePath, "data")
    svcSvc.Register()
    svcSvc.Start()
    del svcSvc

    stackless.getcurrent().block_trap = False
    bootstrapState = STATE_RUNNING

    manualShutdown = False
    try:
        stacklesslibmain.mainloop.run()
    except KeyboardInterrupt:
        print
        print '** EXITING: Server manually stopping.'
        print
        
        if stackless.runcount > 1:
            print "Scheduled tasklets:", stackless.runcount
            uthread2.PrintTaskletChain(stackless.current)
            print

        if False:
            for entry in stacklesslibmain.event_queue.queue_a:
                print "Sleeping tasklets:"
                uthread2.PrintTaskletChain(uthread.yieldChannel.queue)
                print

            for timestamp, channel in uthread.sleepingTasklets:
                if channel.queue:
                    print "Sleep channel (%d) tasklets:" % id(channel)
                    uthread2.PrintTaskletChain(channel.queue)
                    print

        manualShutdown = True
    finally:
        cr.EndMonitoring()

    bootstrapState = STATE_SHUTDOWN

    if manualShutdown:
        class HelperClass:
            def ShutdownComplete(self):
                stacklesslibmain.mainloop.stop()
                managerTasklet.kill()

        helper = HelperClass()
        events.ShutdownComplete.Register(helper.ShutdownComplete)

        stackless.tasklet(sorrows.services.Stop)()
        # We have most likely killed the stacklesssocket tasklet.
        managerTasklet = stacklesssocket.StartManager()
        stacklesslibmain.mainloop.run()

    logging.info("Shutdown complete")
 def _function(self, *args, **kwargs):
     sleep(self._interval)
     if not self._canceled:
         self.function(*args, **kwargs)
 def _function(self, *args, **kwargs):
     sleep(self._interval)
     if not self._canceled:
         self.function(*args, **kwargs)