Search code examples
pythonflaskibm-midrangedb2-400

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:

enter image description here

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

enter image description here

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.


Solution

  • 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