Beispiel #1
0
    def get(self, game_name):
        """
        Get information about happenings in game since optional id
        argument.  Will hang until something happens after id.  If
        nothing happens for long enough, it will redirect to itself.
        """
        opt_id = []
        try:
            if self.get_argument('id'):
                opt_id.append(int(self.get_argument('id')))
        except ValueError:
            pass

        info = game.info(self.db_conn, game_name, self.get_player(game_name),
                         *opt_id)

        try:
            context = coro_timeout.with_timeout(LONGPOLL_TIMEOUT, info.next)
            if is_json_request(self.message):
                self.headers['Content-Type'] = 'application/json'
                self.set_body(json.dumps(context))
                return self.render()
            else:
                context['js_path'] = JS_PATH
                return self.render_template('main', **context)
        except coro_timeout.Timeout:
            if is_json_request(self.message):
                self.set_status(204)
                return self.render()
            else:
                return self.redirect(self.message.path)
Beispiel #2
0
    def get(self):
        """
        List all games currently available.  Only returns if there is
        a game with an ID greater than the provided ID.
        """

        opt_id = []
        try:
            if self.get_argument('id'):
                opt_id.append(int(self.get_argument('id')))
        except ValueError:
            pass

        games = game.games(self.db_conn, *opt_id)

        try:
            context = coro_timeout.with_timeout(LONGPOLL_TIMEOUT, games.next)

            if is_json_request(self.message):
                self.headers['Content-Type'] = 'application/json'
                self.set_body(json.dumps(context))
                return self.render()
            else:
                context['js_path'] = JS_PATH
                return self.render_template('main', **context)
        except coro_timeout.Timeout:
            if is_json_request(self.message):
                self.set_status(204)
                return self.render()
            else:
                return self.redirect(self.message.path)
Beispiel #3
0
def test_with_timeout():
    try:
        result = with_timeout(1, gsleep, 3)
        # result = with_timeout(1, test_with_timeout, 3, timeout_value=-1)
        print 'test_with_timeout timeout_value = %s' % result
    except Timeout:
        print 'test_with_timeout timout exception'
Beispiel #4
0
    def get(self, game_name):
        """
        Get information about happenings in game since optional id
        argument.  Will hang until something happens after id.  If
        nothing happens for long enough, it will redirect to itself.
        """
        opt_id = []
        try:
            if self.get_argument('id'):
                opt_id.append(int(self.get_argument('id')))
        except ValueError:
            pass

        info = game.info(self.db_conn, game_name, self.get_player(game_name), *opt_id)

        try:
            context = coro_timeout.with_timeout(LONGPOLL_TIMEOUT, info.next)
            if is_json_request(self.message):
                self.headers['Content-Type'] = 'application/json'
                self.set_body(json.dumps(context))
                return self.render()
            else:
                context['js_path'] = JS_PATH
                return self.render_template('main', **context)
        except coro_timeout.Timeout:
            if is_json_request(self.message):
                self.set_status(204)
                return self.render()
            else:
                return self.redirect(self.message.path)
Beispiel #5
0
    def get(self):
        """
        List all games currently available.  Only returns if there is
        a game with an ID greater than the provided ID.
        """

        opt_id = []
        try:
            if self.get_argument('id'):
                opt_id.append(int(self.get_argument('id')))
        except ValueError:
            pass

        games = game.games(self.db_conn, *opt_id)

        try:
            context = coro_timeout.with_timeout(LONGPOLL_TIMEOUT, games.next)

            if is_json_request(self.message):
                self.headers['Content-Type'] = 'application/json'
                self.set_body(json.dumps(context))
                return self.render()
            else:
                context['js_path'] = JS_PATH
                return self.render_template('main', **context)
        except coro_timeout.Timeout:
            if is_json_request(self.message):
                self.set_status(204)
                return self.render()
            else:
                return self.redirect(self.message.path)
Beispiel #6
0
    def get(self):
        """
        List all rooms currently available.  Hangs until the number of rooms
        changes.

        This also works as a poll to keep a user in existence.
        """
        id = self.get_id()
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL)

        try:
            id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn, id)
            #self.headers['Refresh'] = refresh
            context = {
                'refresh': "0; url=?id=%d" % id, 
                'rooms': rooms
            }

            rooms.sort()
            rooms.reverse()

            for r in rooms:
                if r['name'] in shit_chans:
                    rooms.remove(r)

            return self.render_template('rooms', **context)
        except timeout.Timeout:
            return self.redirect('?')
Beispiel #7
0
    def get(self, room):
        """
        Render 'limit' messages for this room.  Should hang if there
        are no new messages.
        """
        room = urllib2.unquote(room)
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL, room)
        id = self.get_id()

        try:
            limit = int(self.get_argument('limit') or 25)
        except ValueError:
            limit = 25 

        try:
            id, messages = timeout.with_timeout(TIMEOUT,
                                                chat.messages,
                                                self.db_conn,
                                                room,
                                                limit=limit, id=id)
            context = {
                'refresh': "0; url=?id=%d#bottom" % id,
                'messages': messages,
                'room': room
            }
            return self.render_template('messages', **context)
            #self.headers['Refresh'] = refresh
        except timeout.Timeout:
            return self.redirect('?#bottom') 
    def start(self, **kwargs):
        '''Prepares worker based on parameter passed on constructor and
        optional ``kwargs``
        '''
        merged_kwargs = {}
        merged_kwargs.update(self.kwargs)
        merged_kwargs.update(kwargs)
        worker_timeout = merged_kwargs.pop('timeout', 6.0)
        worker_callback = merged_kwargs.pop('callback', None)
        worker_exception = merged_kwargs.pop('exception_handler', None)

        try:
            self.response = timeout.with_timeout(worker_timeout, self.func,
                                                 *self.args, **merged_kwargs)

            if worker_callback:
                self.respnose = worker_callback(self.response)
        except Exception as e:
            self.exception = e

            if worker_exception:
                self.exception = worker_exception(self.exception)
            self.traceback = traceback.format_exc()

        return self
Beispiel #9
0
    def get(self, room):
        """
        Render 'limit' messages for this room.  Should hang if there
        are no new messages.
        """
        room = urllib.parse.unquote(room)

        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL, room)
        id = self.get_id()

        try:
            limit = int(self.get_argument('limit') or 255)
        except ValueError:
            limit = 255

        try:
            id, messages = timeout.with_timeout(TIMEOUT,
                                                chat.messages,
                                                self.db_conn,
                                                room,
                                                limit=limit,
                                                id=id)
            context = {
                'refresh': "0; url=?id=%d#bottom" % id,
                'messages': messages,
                'room': room
            }
            return self.render_template('messages', **context)
            #self.headers['Refresh'] = refresh
        except timeout.Timeout:
            return self.redirect('?#bottom')
Beispiel #10
0
    def get(self, room):
        """
        Render the users currently in the room.  Hangs if nothing has happened
        since ID.

        This also functions as a poll for whether a user is still in a room.
        """
        room = urllib.parse.unquote(room)
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL, room)
        id = self.get_id()
        try:
            id, users = timeout.with_timeout(TIMEOUT,
                                             chat.users,
                                             self.db_conn,
                                             room,
                                             id=id)
            #self.headers['Refresh'] = refresh
            context = {
                'room': room,
                'users': users,
                'refresh': "0; url=?id=%d" % id
            }
            return self.render_template('users', **context)
        except timeout.Timeout:
            return self.redirect('?')
Beispiel #11
0
    def get(self):
        """
        List all rooms currently available.  Hangs until the number of rooms
        changes.

        This also works as a poll to keep a user in existence.
        """
        id = self.get_id()
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL)

        try:
            id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn,
                                             id)
            #self.headers['Refresh'] = refresh
            context = {'refresh': "0; url=?id=%d" % id, 'rooms': rooms}

            rooms.sort()
            rooms.reverse()

            for r in rooms:
                if r['name'] in shit_chans:
                    rooms.remove(r)

            return self.render_template('rooms', **context)
        except timeout.Timeout:
            return self.redirect('?')
Beispiel #12
0
 def pool_task_with_timeout(self, line):
     seed = line.strip()
     result = dict(seed=seed, data=None, exception=None)
     try:
         data = timeout.with_timeout(self.pool_timeout, self.scan_func,
                                     seed)
     except (Exception, timeout.Timeout) as ex:
         result['exception'] = str(ex)
     else:
         result['data'] = data
     return result
Beispiel #13
0
 def pool_task_with_timeout(self, line):
     seed = line.strip()
     result = dict(seed=seed, data=None, exception=None)
     try:
         data = timeout.with_timeout(self.pool_timeout,
                                     self.scan_func,
                                     seed)
     except (Exception, timeout.Timeout) as ex:
         result['exception'] = str(ex)
     else:
         result['data'] = data
     return result
Beispiel #14
0
    def get(self):
        """
        List all rooms currently available.  Hangs until the number of rooms
        changes.

        This also works as a poll to keep a user in existence.
        """
        id = self.get_id()
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL)

        try:
            id, rooms = timeout.with_timeout(TIMEOUT, chat.rooms, self.db_conn, id)
            # self.headers['Refresh'] = refresh
            context = {"refresh": "0; url=?id=%d" % id, "rooms": rooms}
            return self.render_template("rooms", **context)
        except timeout.Timeout:
            return self.redirect("?")
Beispiel #15
0
    def get(self, room):
        """
        Render the users currently in the room.  Hangs if nothing has happened
        since ID.

        This also functions as a poll for whether a user is still in a room.
        """
        room = urllib2.unquote(room)
        user = self.get_user()
        if user:
            chat.touch(self.db_conn, user, TTL, room)
        id = self.get_id()
        try:
            id, users = timeout.with_timeout(TIMEOUT, chat.users, self.db_conn, room, id=id)
            # self.headers['Refresh'] = refresh
            context = {"room": room, "users": users, "refresh": "0; url=?id=%d" % id}
            return self.render_template("users", **context)
        except timeout.Timeout:
            return self.redirect("?")