Example #1
0
    def __init__(self, config=None, noisy=True):
        """config is a dict that contains option-value pairs.
        """
        RawServerMixin.__init__(self, config, noisy)

        self.doneflag = None

        # init is fine until the loop starts
        self.ident = thread.get_ident()
        self.associated = False

        self.single_sockets = set()
        self.unix_sockets = set()
        self.udp_sockets = set()
        self.listened = False
        self.connections = 0

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

        self.connection_limit = self.config.get('max_incomplete', 10)
        connectionRateLimitReactor(reactor, self.connection_limit)

        # bleh
        self.add_pending_connection = reactor.add_pending_connection
        self.remove_pending_connection = reactor.remove_pending_connection
        self.reactor = reactor

        self.reactor.resolver = SaneThreadedResolver(self.reactor)
Example #2
0
    def OnInit(self):
        self.running = True
        if profile:
            try:
                os.unlink(prof_file_name)
            except:
                pass
            self.prof = Profiler()
            self.prof.enable()

        wx.the_app = self
        self._DoIterationId = wx.NewEventType()
        self.Connect(-1, -1, self._DoIterationId, self._doIteration)
        self.evt = wx.PyEvent()
        self.evt.SetEventType(self._DoIterationId)
        self.event_queue = []

        # this breaks TreeListCtrl, and I'm too lazy to figure out why
        #wx.IdleEvent_SetMode(wx.IDLE_PROCESS_SPECIFIED)
        # this fixes 24bit-color toolbar buttons
        wx.SystemOptions_SetOptionInt("msw.remap", 0)
        icon_path = os.path.join(image_root, 'bittorrent.ico')
        self.icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        return True
Example #3
0
    def OnInit(self):
        self.running = True
        if profile:
            try:
                os.unlink(prof_file_name)
            except:
                pass
            self.prof = Profiler()
            self.prof.enable()
        
        wx.the_app = self
        self._DoIterationId = wx.NewEventType()
        self.Connect(-1, -1, self._DoIterationId, self._doIteration)
        self.evt = wx.PyEvent()
        self.evt.SetEventType(self._DoIterationId)
        self.event_queue = []

        # this breaks TreeListCtrl, and I'm too lazy to figure out why
        #wx.IdleEvent_SetMode(wx.IDLE_PROCESS_SPECIFIED)
        # this fixes 24bit-color toolbar buttons
        wx.SystemOptions_SetOptionInt("msw.remap", 0)
        icon_path = os.path.join(image_root, 'bittorrent.ico')
        self.icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        return True
Example #4
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)

Example #5
0
class BTApp(wx.App):
    """Base class for all wx-based BitTorrent applications"""

    def __init__(self, *a, **k):
        self.doneflag = threading.Event()
        wx.App.__init__(self, *a, **k)

    def OnInit(self):
        self.running = True
        if profile:
            try:
                os.unlink(prof_file_name)
            except:
                pass
            self.prof = Profiler()
            self.prof.enable()
        
        wx.the_app = self
        self._DoIterationId = wx.NewEventType()
        self.Connect(-1, -1, self._DoIterationId, self._doIteration)
        self.evt = wx.PyEvent()
        self.evt.SetEventType(self._DoIterationId)
        self.event_queue = []

        # this breaks TreeListCtrl, and I'm too lazy to figure out why
        #wx.IdleEvent_SetMode(wx.IDLE_PROCESS_SPECIFIED)
        # this fixes 24bit-color toolbar buttons
        wx.SystemOptions_SetOptionInt("msw.remap", 0)
        icon_path = os.path.join(image_root, 'bittorrent.ico')
        self.icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        return True

    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)

    def who(self, _f, a):
        if _f.__name__ == "_recall":
            if not hasattr(a[0], 'gen'):
                return str(a[0])
            return a[0].gen.gi_frame.f_code.co_name
        return _f.__name__

    def _doIteration(self, event):

        if self.doneflag.isSet():
            # the app is dying
            return

        _f, a, kw = self.event_queue.pop(0)

##        t = bttime()
##        print self.who(_f, a)
        _f(*a, **kw)
##        print self.who(_f, a), 'done in', bttime() - t
##        if bttime() - t > 1.0:
##            print 'TOO SLOW!'
##            assert False

    def CallAfter(self, callable, *args, **kw):
        """
        Call the specified function after the current and pending event
        handlers have been completed.  This is also good for making GUI
        method calls from non-GUI threads.  Any extra positional or
        keyword args are passed on to the callable when it is called.
        """

        # append (right) and pop (left) are atomic
        self.event_queue.append((callable, args, kw))
        wx.PostEvent(self, self.evt)

    def FutureCall(self, _delay_time, callable, *a, **kw):
        return wx.FutureCall(_delay_time, self.CallAfter, callable, *a, **kw)
Example #6
0
class BTApp(wx.App):
    """Base class for all wx-based BitTorrent applications"""
    def __init__(self, *a, **k):
        self.doneflag = threading.Event()
        wx.App.__init__(self, *a, **k)

    def OnInit(self):
        self.running = True
        if profile:
            try:
                os.unlink(prof_file_name)
            except:
                pass
            self.prof = Profiler()
            self.prof.enable()

        wx.the_app = self
        self._DoIterationId = wx.NewEventType()
        self.Connect(-1, -1, self._DoIterationId, self._doIteration)
        self.evt = wx.PyEvent()
        self.evt.SetEventType(self._DoIterationId)
        self.event_queue = []

        # this breaks TreeListCtrl, and I'm too lazy to figure out why
        #wx.IdleEvent_SetMode(wx.IDLE_PROCESS_SPECIFIED)
        # this fixes 24bit-color toolbar buttons
        wx.SystemOptions_SetOptionInt("msw.remap", 0)
        icon_path = os.path.join(image_root, 'bittorrent.ico')
        self.icon = wx.Icon(icon_path, wx.BITMAP_TYPE_ICO)
        return True

    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)

    def who(self, _f, a):
        if _f.__name__ == "_recall":
            if not hasattr(a[0], 'gen'):
                return str(a[0])
            return a[0].gen.gi_frame.f_code.co_name
        return _f.__name__

    def _doIteration(self, event):

        if self.doneflag.isSet():
            # the app is dying
            return

        _f, a, kw = self.event_queue.pop(0)

        ##        t = bttime()
        ##        print self.who(_f, a)
        _f(*a, **kw)
##        print self.who(_f, a), 'done in', bttime() - t
##        if bttime() - t > 1.0:
##            print 'TOO SLOW!'
##            assert False

    def CallAfter(self, callable, *args, **kw):
        """
        Call the specified function after the current and pending event
        handlers have been completed.  This is also good for making GUI
        method calls from non-GUI threads.  Any extra positional or
        keyword args are passed on to the callable when it is called.
        """

        # append (right) and pop (left) are atomic
        self.event_queue.append((callable, args, kw))
        wx.PostEvent(self, self.evt)

    def FutureCall(self, _delay_time, callable, *a, **kw):
        return wx.FutureCall(_delay_time, self.CallAfter, callable, *a, **kw)