简体   繁体   中英

Running a Flask app on an IBM i results in error "Can't start new thread"

I use an IBM i at work and can successfully run basic Python scripts, but can't run a Flask app. When I run the app it appears to launch, but when browsing to the app in my browser, the app throws errors about not being able to start a new thread. I'm guessing this is something related to the IBM i and not Python or Flask.

from flask import Flask                                                                                                            
import ibm_db_dbi as db2                                                                                                           
app = Flask(__name__)                                                                                                              
                                                                                                                                   
@app.route('/<username>')                                                                                                          
def get_email(username):                                                                                                           
    return f'Hello {username}!'

I run this app from Qshell like this:

export PATH=/QOpenSys/pkgs/bin:$PATH
export FLASK_APP=index.py
flask run --host=0.0.0.0

This is the output on the console:

在此处输入图像描述

When I browse to the route, this is the error I get:

在此处输入图像描述

I tried running another example with Bottle https://bottlepy.org/docs/dev/ and this one seems to work. I assume that Bottle is not trying to start a new thread. I would ideally like to get it working with Flask though.

You don't mention which Python you're running, hopefully the recommended 3.6 installed via yum .

But sounds like you don't have multi-threading enabled...

QIBM_MULTI_THREADED (Start multi-thread capable processes) This variable determines if processes started by qsh can create multiple threads. When the value of the variable is "Y", all child processes started by qsh can start threads. The default value is "N".

 Change Environment Variable (CHGENVVAR)

Type choices, press Enter.

Environment variable. . . . . . > QIBM_MULTI_THREADED

New value. . . . . . . . . . . Y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM