Example #1
0
 def input_handler(self):
     nick = thread(self.read_chat_message, "nick: ").strip()
     self.nick = nick
     self.input.put(nick)
     while True:
         msg = thread(self.read_chat_message, "").strip()
         self.input.put(msg)
Example #2
0
 def input_handler(self):
     nick = thread(self.read_chat_message, "nick: ").strip()
     self.nick = nick
     self.input.put(nick)
     while True:
         msg = thread(self.read_chat_message, "").strip()
         self.input.put(msg)
Example #3
0
def blocker():
    x = 1
    while True:
        def f():
            time.sleep(1)
        thread(f)
        print 'yo!', time.time()
Example #4
0
def blocker(taskid, sleep_time):
    while True:

        def f():
            time.sleep(sleep_time)

        thread(f)
        log.info('yo! {0} from {1} task', time.time(), taskid)
Example #5
0
def blocker():
    x = 1
    while True:

        def f():
            time.sleep(1)

        thread(f)
        print 'yo!', time.time()
Example #6
0
def track_cpu_stats():
    pid = os.getpid()
    def append_stats():
        rawstats = subprocess.Popen(['ps -p %d -f' % pid], shell=True, stdout=subprocess.PIPE).communicate()[0]
        header, data = rawstats.split('\n', 1)
        procstats = [d for d in data.split(' ') if d]
        cpustats.append(int(procstats[3]))
    while True:
        diesel.sleep(1)
        diesel.thread(append_stats)
Example #7
0
def track_cpu_stats():
    pid = os.getpid()

    def append_stats():
        rawstats = subprocess.Popen(['ps -p %d -f' % pid],
                                    shell=True,
                                    stdout=subprocess.PIPE).communicate()[0]
        header, data = rawstats.split('\n', 1)
        procstats = [d for d in data.split(' ') if d]
        cpustats.append(int(procstats[3]))

    while True:
        diesel.sleep(1)
        diesel.thread(append_stats)
Example #8
0
def test_signals_are_handled_while_event_loop_is_blocked():
    done = Event()

    def handler():
        diesel.signal(signal.SIGUSR1)
        done.set()

    def killer():
        time.sleep(0.1)
        os.kill(os.getpid(), signal.SIGUSR1)

    diesel.fork(handler)
    diesel.thread(killer)
    diesel.sleep()
    evt, _ = diesel.first(sleep=1, waits=[done])
    assert evt is done
Example #9
0
def resolve_dns_name(name):
    """Given a hostname `name`, invoke the socket.gethostbyname function
    to retreive the A (IPv4 only) record on a background thread.

    Keep a cache.
    """
    try:
        ip, tm = cache[name]
        if time.time() - tm > DNS_CACHE_TIME:
            del cache[name]
            cache[name]
    except KeyError:
        try:
            ip = thread(socket.gethostbyname, name)
        except socket.gaierror:
            raise DNSResolutionError("could not resolve A record for %s" % name)
        cache[name] = ip, time.time()
        return resolve_dns_name(name)
    else:
        return ip
Example #10
0
def resolve_dns_name(name):
    '''Given a hostname `name`, invoke the socket.gethostbyname function
    to retreive the A (IPv4 only) record on a background thread.

    Keep a cache.
    '''
    try:
        ip, tm = cache[name]
        if time.time() - tm > DNS_CACHE_TIME:
            del cache[name]
            cache[name]
    except KeyError:
        try:
            ip = thread(socket.gethostbyname, name)
        except socket.gaierror:
            raise DNSResolutionError("could not resolve A record for %s" %
                                     name)
        cache[name] = ip, time.time()
        return resolve_dns_name(name)
    else:
        return ip
Example #11
0
 def task():
     while True:
         def f():
             time.sleep(sleep_time)
         thread(f)
         print 'yo!', time.time(), 'from %s task' % taskid
Example #12
0
def blocker(taskid, sleep_time):
    while True:
        def f():
            time.sleep(sleep_time)
        thread(f)
        log.info('yo! {0} from {1} task', time.time(), taskid)