1

Recently, company test the API that I developed. (Use Flask)
If a new user connect, I need to create a thread to process his request.
When it came to about 2000 users. It showed

File "C:\python27\Lib\threading.py", line 494, in start
  _start_new_thread(self.__bootstrap, ())
error: can't start new thread

I've surveyed related question. But still don't know how to solve this problem.
Is there any parameter that I can increase the thread number ?
Or
How can I solve this problem?

I will thank you so so so much ~!!

h8a2n5k23
  • 57
  • 1
  • 7
  • Creating a thread for each new request isn't going to be feasable for any real world application. Short term solution is available here: https://stackoverflow.com/a/344292/6313992 This is however hardware dependant, OS dependant and environment dependant. In practice noone does this in such way in any reasonable application. – Tomasz Plaskota May 24 '17 at 11:39
  • @TomaszPlaskota That answer only applies to linux, `C:\...` hints that the OP is using windows where things like thread limits are even more complicated... My advise would be: Don't write your own server code, use an existing wsgi container to deploy your flask app. Creating threads or preforked processes to process the requests should be the job of the container (e.g. apache/nginx/... + mod_wsgi/uwsgi/...), if you need to create your own threads there's something not quite right with your design. – mata May 24 '17 at 12:05
  • Yeah, pretty much that. I was answering more the question about increasing thread limit. But indeed, server shouldn't be done this way. Running thread per request is prototype type of approach, like it might be presented in tutorial books. It should either default to wsgi interface or if you really want application to manage threads then thread pool of few threads for processing and synchronous message queue for incomming requests as well as manager to contain processing logic. – Tomasz Plaskota May 24 '17 at 13:15
  • @TomaszPlaskota I have a requirement that if the user were motionless about 5 mins, I have to save the data that he've posted. So I create thread for everyone so that I can process individually. Or is there any better way to implement my requirement ? XD – h8a2n5k23 May 25 '17 at 06:21
  • @mata Thanks for your reply, Maybe I have to survey the container which you mentioned. But most of them seems only support Linux... Haha – h8a2n5k23 May 25 '17 at 06:27

0 Answers0