コード例 #1
0
ファイル: stream.py プロジェクト: milkey-mouse/basket
 def generate_mjpg_stream():
     #view = uwsgi.sharedarea_memoryview(0)
     while True:
         yield b"--frame\r\n"
         yield b"Content-Type: image/jpeg\r\n\r\n"
         uwsgi.sharedarea_wait(0)
         yield uwsgi.sharedarea_read(0, 0)
         yield b"\r\n"
コード例 #2
0
def set_global_log_level(expire_timestamp):
    timer_ = expire_timestamp - int(time.time())
    time.sleep(int(timer_))
    try:
        default_log_level = uwsgi.sharedarea_read(0, 0, 3)
        global_level = int(default_log_level.decode('ascii'))
        uwsgi.sharedarea_write(0, 3, json.dumps(global_level))
    except NameError:
        pass
コード例 #3
0
 def update_level(self, message, *args, **kwargs) -> func:
     try:
         shared_log_level = uwsgi.sharedarea_read(0, 3, 3)
         global_level = int(shared_log_level.decode('ascii'))
     except NameError:
         global_level = self.level
     if self.level != global_level:
         self.setLevel(global_level)
     return func(self, message, *args, **kwargs)
コード例 #4
0
    def read_shared_area(self):
        # read payload len
        len_ = sharedarea_read32(self.id, 0)

        # read payload
        if len_ > 0:
            json_ = sharedarea_read(self.id, 4, len_)
            self.data = json.loads(json_)
        else:
            self.data = {}
コード例 #5
0
ファイル: __init__.py プロジェクト: Shevraar/jovabot
    def read_shared_area(self):
        # read payload len
        len_ = sharedarea_read32(self.id, 0)

        # read payload
        if len_ > 0:
            json_ = sharedarea_read(self.id, 4, len_)
            self.data = json.loads(json_)
        else:
            self.data = {}
コード例 #6
0
def application(e, sr):

    sr('200 Ok', [('Content-Type', 'text/html')])

    uwsgi.sharedarea_write(17, e['REQUEST_URI'])

    uwsgi.sharedarea_inclong(173)
    uwsgi.sharedarea_inclong(173, 17)

    yield uwsgi.sharedarea_read(17, len(e['REQUEST_URI']))
    yield "<br/>"
    yield str(uwsgi.sharedarea_readlong(173))
コード例 #7
0
def level_runtime(request) -> Response:

    if request.method == 'GET':
        try:
            shared_area = uwsgi.sharedarea_read(0, 3, 3)
            level = int(shared_area.decode('utf-8'))
        except:
            level = logger.level
        context = {
            "level_number": 109 - level
        }
        response = jsonify(context)
        response.status_code = 200

    elif request.method == 'POST':
        if request.is_json and request.data:
            payload = request.get_json()
            if 'level_number' not in payload:
                raise InvalidUsage(status_code=412, message='level_number not found in payload')
            elif type(payload['level_number']) is not int or not 0 <= payload['level_number'] <= 9:
                raise InvalidUsage(status_code=412, message='level_number is not a number or not between 0 and 9')
            else:
                level = payload.get('level_number', 9)
                real_level = int(get_real_logger_level(int(level)))
                expire_hours = payload.get('expire_hours', 0)
                expire_timestamp = int(time.time()) + int(float(expire_hours) * 3600) if expire_hours else 0
                payload = {
                    "level_number": level,
                    "expire_hours": expire_hours
                }
                try:
                    if expire_hours == 0:
                        uwsgi.sharedarea_write(0, 0, json.dumps(real_level))
                    else:
                        timer_thread = threading.Thread(target=set_global_log_level, args=(expire_timestamp,),
                                                        name='Timer',
                                                        daemon=True)
                        timer_thread.start()
                    uwsgi.sharedarea_write(0, 3, json.dumps(real_level))
                except NameError:
                    logger.setLevel(real_level)

                response = jsonify(payload)
                response.status_code = 200

        else:
            raise InvalidUsage('No data or data format invalid.', status_code=422)
    else:
        raise InvalidUsage('The method is not allowed for the requested URL.', status_code=405)

    return response