3

my flask app does the following : user uploads file - file gets processed -->flask returns file

I was curios what does happen if two users simultaneous access the website and perform the same task.

I used selenium server in combination with ray to perform a simultaneous request on the app

code in short form

ray.init()

@ray.remote
def parallel_1():
    driver = webdriver.Remote(
        command_executor="http://localhost:4444/wd/hub",
        desired_capabilities={
            "browserName": "chrome",
        })

# do task


ret_id1 = parallel_1.remote()
ret_id2 = parallel_1.remote()
ret1, ret2 = ray.get([ret_id1, ret_id2])


the flask view functions are plane simple no threads or sessions, is there something going on under the hood what Im not aware off ? or how does flask handle simultaneous requests ?

davidism
  • 121,510
  • 29
  • 395
  • 339
Sator
  • 636
  • 4
  • 13
  • 34

1 Answers1

5

Flask doesn't. Parallel request handling is the task of the underlying WSGI web server, which sends the requests to Flask for handling.

Flask's built-in development server which is invoked with Flask.run() runs with threads by default

In production, you'd use one of the WSGI containers or other deployment options, and you control parallelism there. Gunicorn, for example, has the -w command line argument which controls the number of worker processes, and -k which controls how these workers work (processes, threads, or a Tornado event machine, among others).

davidism
  • 121,510
  • 29
  • 395
  • 339
Thomas
  • 174,939
  • 50
  • 355
  • 478