1

We developed a Flask webapp, and want to deploy it on IIS. During development, we started the app via flask run, which lanches a single instance of our app. On IIS, however, we observed (via the task manager) that our app runs multiple instances concurrently.

The problem is that our app is not designed to run in parallel. For example, our app reads a file from the file system and keeps it in memory for efficiency. This optimization is correct only if it is guaranteed that no other process changes the content of the file.

Is there a way to prevent IIS from starting multiple instances?

Kasper Dokter
  • 91
  • 1
  • 5
  • How did you host Python apps on IIS? If you use HttpPlatformHandler, it has a setting ˋprocessesPerApplicationˋ to run only a single instance of your Flask app, https://learn.microsoft.com/en-us/iis/extensions/httpplatformhandler/httpplatformhandler-configuration-reference#httpplatformhandler-configuration – Lex Li Aug 05 '20 at 19:29

2 Answers2

1

In IIS, you can go to FastCGI settings, in there you can see all the applications used by websites on your server. In the column "Max. Instances", the script you are talking about is probably set to 0 (or some value greater than 1), meaning it can be started multiple times. Limiting this to 1 will solve your problem.

Dennis
  • 120
  • 1
  • 8
0

you could use below code to run only one instance of a program:

from tendo import singleton
me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running

the command to install:

pip install tendo

Reference link:

Check to see if python script is running

How to make only one instance of the same script running at any time

https://github.com/pycontribs/tendo/blob/master/tendo/singleton.py

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26