示例#1
0
 def OnExit(self):
     self.running = False
     if profile:
         self.prof.disable()
         st = Stats(self.prof.getstats())
         st.sort()
         f = open(prof_file_name, 'wb')
         st.dump(file=f)
示例#2
0
    def listen_forever(self, doneflag=None):
        """Main event processing loop for RawServer.
           RawServer listens until the doneFlag is set by some other
           thread.  The doneFlag tells all threads to clean-up and then
           exit."""

        if not doneflag:
            doneflag = DeferredEvent()
        assert isinstance(doneflag, DeferredEvent)
        self.doneflag = doneflag

        if not self.associated:
            self.associate_thread()

        if self.listened:
            Exception(_("listen_forever() should only be called once per reactor."))

        if main_thread == thread.get_ident() and not self.sigint_installed:
            self.install_sigint_handler()

        if is_iocpreactor and main_thread == thread.get_ident():
            def pulse():
                self.add_task(1, pulse)
            pulse()

        reactor.callLater(0, self.doneflag.addCallback, self._safestop)
        self.listened = True

        reactor.suggestThreadPoolSize(3)

        if profile:
            self.prof.enable()
        
        if noSignals:
            reactor.run(installSignalHandlers=False)
        else:
            reactor.run()

        if profile:
            self.prof.disable()
            st = Stats(self.prof.getstats())
            st.sort()
            f = open(prof_file_name, 'wb')
            st.dump(file=f)
示例#3
0
 def OnExit(self):
     self.running = False
     if profile:
         self.prof.disable()
         st = Stats(self.prof.getstats())
         st.sort()
         f = open(prof_file_name, 'wb')
         st.dump(file=f)
示例#4
0
    def listen_forever(self, doneflag=None):
        """Main event processing loop for RawServer.
           RawServer listens until the doneFlag is set by some other
           thread.  The doneFlag tells all threads to clean-up and then
           exit."""

        if not doneflag:
            doneflag = DeferredEvent()
        assert isinstance(doneflag, DeferredEvent)
        self.doneflag = doneflag

        if not self.associated:
            self.associate_thread()

        if self.listened:
            Exception(
                _("listen_forever() should only be called once per reactor."))

        if main_thread == thread.get_ident() and not self.sigint_installed:
            self.install_sigint_handler()

        if is_iocpreactor and main_thread == thread.get_ident():

            def pulse():
                self.add_task(1, pulse)

            pulse()

        reactor.callLater(0, self.doneflag.addCallback, self._safestop)
        self.listened = True

        reactor.suggestThreadPoolSize(3)

        if profile:
            self.prof.enable()

        if noSignals:
            reactor.run(installSignalHandlers=False)
        else:
            reactor.run()

        if profile:
            self.prof.disable()
            st = Stats(self.prof.getstats())
            st.sort()
            f = open(prof_file_name, 'wb')
            st.dump(file=f)
示例#5
0
    t = task.LoopingCall(push)
    t.start(freq)
    
##    m = MultiRateLimiter(sched=rawserver.add_task)
##    m.set_parameters(120000000)
##    class C(object):
##        def send_partial(self, size):
##            global_rate.print_rate(size)
##            rawserver.add_task(0, m.queue, self)
##            return size
##            
##    m.queue(C())

    if profile:
        try:
            os.unlink(prof_file_name)
        except:
            pass
        prof = Profiler()
        prof.enable()

    rawserver.listen_forever()

    if profile:
        prof.disable()
        st = Stats(prof.getstats())
        st.sort()
        f = open(prof_file_name, 'wb')
        st.dump(file=f)