Supervisor / supervisor

Supervisor process control system for Unix (supervisord)
http://supervisord.org
Other
8.53k stars 1.25k forks source link

Two returns are not supported? #1544

Closed jiahe224 closed 2 years ago

jiahe224 commented 2 years ago

When the second if in the function is satisfied, it can be executed to the penultimate line, but the result cannot be returned properly. But the first if is satisfied and the result is returned normally

def getServerNum():
    ....
    if get_type == 'msisdn':
        SN_In_ROI = gn.send_phone(regionId, eventId)
        return jsonify(SN_In_ROI)
    elif get_type == 'cop':
        print ('get_type(2) is:', get_type, flush=True)
        cop_in_ROI = gn.count_of_people(regionId)
        print ('cop_in_ROI is:', cop_in_ROI, flush=True)
        return jsonify(cop_in_ROI)

When the code is modified, running the supervisord command does not start properly .

def getServerNum():
    ....
    if get_type == 'msisdn':
        SN_In_ROI = gn.send_phone(regionId, eventId)
        result = jsonify(SN_In_ROI)
    elif get_type == 'cop':
        print ('get_type(2) is:', get_type, flush=True)
        cop_in_ROI = gn.count_of_people(regionId)
        print ('cop_in_ROI is:', cop_in_ROI, flush=True)
        result = jsonify(cop_in_ROI)
    return result

Running gn.count_of_people(regionId) alone will return normal results. The omitted code is as follows

from flask import Blueprint, request, jsonify
import json
import GetServerNumPre_RT as gn

Pre_RT = Blueprint('Pre_RT', __name__)
@Pre_RT.route("/getServerNum", methods=["POST"])

def getServerNum():
    print ('                 ', flush=True)
    print ('------ 分割线 ------', flush=True)
    print ('输入参数值为:', request.data, flush=True)

    data = json.loads(request.data)  # 将json字符串转为dict
    print ('解析输入成功,解析后为:', data, flush=True)

    try:
        if type(data['regionId']) is list:
            regionId = data['regionId'][0]
        else:
            regionId = data['regionId']
        print ('regionId is:', regionId, flush=True)
    except:
        BS_In_ROI = {"statusCode": "0001", "statusMsg": "输入参数有误", "msisdn": ""}
        return jsonify(BS_In_ROI)

    try:
        if type(data['eventId']) is list:
            eventId = data['eventId'][0]
        else:
            eventId = data['eventId']
    except:
        eventId = None
    print ('eventId is:', eventId, flush=True)

    if type(data['type']) is list:
        get_type = data['type'][0]
    else:
        get_type = data['type']

    print ('get_type(1) is:', get_type, flush=True)

The following code runs fine in ipython and returns results.

from flask import Blueprint, request, jsonify
import json
import GetServerNumPre_RT as gn

data_input = '{"regionId":"region_id_test","type":"cop"}'

#Pre_RT = Blueprint('Pre_RT', __name__)
#@Pre_RT.route("/getServerNum", methods=["POST"])

def getServerNum():
    print ('                 ')
    print ('------ 分割线 ------')

    data = json.loads(data_input)  # 将json字符串转为dict
    print ('解析输入参数成功')

    try:
        if type(data['regionId']) is list:
            regionId = data['regionId'][0]
        else:
            regionId = data['regionId']
    except:
        BS_In_ROI = {"statusCode": "0001", "statusMsg": "输入参数有误", "msisdn": ""}
        return (BS_In_ROI)
    print ('regionId is ', regionId)

    try:
        if type(data['eventId']) is list:
            eventId = data['eventId'][0]
        else:
            eventId = data['eventId']
    except:
        eventId = None
    print ('eventId is ', eventId)

    if type(data['type']) is list:
        get_type = data['type'][0]
    else:
        get_type = data['type']

    print ('get_type(1) is ', get_type)

    if get_type == 'msisdn':
        SN_In_ROI = gn.send_phone(regionId, eventId)
        return (SN_In_ROI)
    elif get_type == 'cop':
        print ('get_type(2) is ', get_type)
        cop_in_ROI = gn.count_of_people(regionId)
        print (cop_in_ROI )
        return (cop_in_ROI )

Env: supervisord -v 4.2.4 python -v 3.8.8 Linux version 3.10.0-693.21.1.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) )

jiahe224 commented 2 years ago

I Found the problem, because jsonify() doesn't support numpy's int64