Exemplo n.º 1
0
def _got_result(ip):
    global _host_ip
    global _host_ip_callbacks
    global _host_ip_cachetime
    global _thread_running
    if hasattr(reactor, 'ident'):
        assert reactor.ident == thread.get_ident()

    if _thread_running:
        return

    if ip is None:
        t = threading.Thread(target=_resolve)
        t.setDaemon(True)
        _thread_running = True
        t.start()
        return

    if ip is not 'unknown':
        _host_ip = ip
        _host_ip_cachetime = bttime()

    l = _host_ip_callbacks
    _host_ip_callbacks = []
    for df in l:
        df.callback(_host_ip)
Exemplo n.º 2
0
 def set_nodes_restart(self, nodes):
     if len(nodes) > 10:
         nodes = random.sample(nodes, 10)
     else:
         nodes = list(nodes)
     t = threading.Thread(target=self.run, args=(nodes, ))
     t.setDaemon(True)
     t.start()
Exemplo n.º 3
0
 def set_nodes_restart(self, nodes):
     if debug:
         pprint("set_nodes_restart: nodes=%s" % str(nodes))
     self.nodes = []
     for node in nodes:
         self.add_node(node)
     t = threading.Thread(target=self.run, args=(list(self.nodes), ))
     t.setDaemon(True)
     t.start()
Exemplo n.º 4
0
    def update(self, doc=None):
        if self.thread is not None:
            if self.thread.isAlive():
                return True

        self.thread = threading.Thread(target=self._update, args=(doc, ))
        self.thread.setDaemon(True)
        self.main.show_status("Downloading %s" % self.url)
        self.main.ui_wrap_func(self.thread.start)
        return True
Exemplo n.º 5
0
 def __init__(self, queue_func, f, *args, **kwargs):
     Deferred.__init__(self)
     daemon = False
     if 'daemon' in kwargs:
         daemon = kwargs.pop('daemon')
     self.f = f
     start = True
     if queue_func is None:
         start = False
         queue_func = lambda f, *a, **kw: f(*a, **kw)
     self.queue_func = queue_func
     self.args = args
     self.kwargs = kwargs
     self.t = threading.Thread(target=self.run)
     self.t.setDaemon(daemon)
     if start:
         self.start()
Exemplo n.º 6
0
    def __init__(self, doneflag, add_task, external_add_task,
                 max_files_open, num_disk_threads):
        self.doneflag = doneflag
        self.external_add_task = external_add_task
        self.file_to_torrent = {}

        self.free_handle_condition = threading.Condition()
        self.active_file_to_handles = DictWithSets()
        self.open_file_to_handles = DictWithLists()

        self.set_max_files_open(max_files_open)

        self.diskq = Queue.Queue()
        for i in xrange(num_disk_threads):
            t = threading.Thread(target=self._disk_thread,
                                 name="disk_thread-%s" % (i+1))
            t.start()

        self.doneflag.addCallback(self.finalize)
Exemplo n.º 7
0
 def visit_url(self, url, callback=None):
     """Visit a URL in the user's browser"""
     t = threading.Thread(target=self._visit_url, args=(url, callback))
     t.start()
Exemplo n.º 8
0
 def new_channel(self, url):
     thread = threading.Thread(target=self._new_channel, args=(url, ))
     thread.setDaemon(True)
     self.ui_wrap_func(thread.start)
Exemplo n.º 9
0
            # one message for the user w/o info
            global_logger.critical("BitTorrent core initialization failed!")

            core_doneflag.set()
            rawserver.stop()
            try:
                gui_wrap(mainloop.ExitMainLoop)
            except:
                pass
            try:
                gui_wrap(mainloop.doneflag.set)
            except:
                pass
            raise

    threading.Thread(target=init_core, args=(mainloop, )).start()

    mainloop.append_external_torrents(*args)

    ##    # cause memleak stuff to be imported
    ##    import code
    ##    import sizer
    ##
    ##    from sizer import annotate
    ##    from sizer import formatting
    ##    from sizer import operations
    ##    from sizer import rules
    ##    from sizer import scanner
    ##    from sizer import set
    ##    from sizer import sizes
    ##    from sizer import wrapper
Exemplo n.º 10
0
def daemon_thread(target, args=()):
    t = threading.Thread(target=target, args=args)
    t.setDaemon(True)
    return t
Exemplo n.º 11
0
 def __init__(self):
     self.thread = threading.Thread(target=self.run)
     self.queue = Queue.Queue()
     self.killswitch = threading.Event()