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__)                                                                                                              
def get_email(username):                                                                                                           
    return f'Hello {username}!'

I run this app from Qshell like this:

export PATH=/QOpenSys/pkgs/bin:$PATH
flask run --host=

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 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

Answered By – Charles

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published