Hello to all. There is a web application on flask (Python 3). Post data is sent to it with a request (VK api), the application must process it. The result (what is sent in response to the request, return 'ok', 200) must always be the same. The task is this: Accept the request, send it "further along the code." In parallel with this, make a return or send this message ('ok') and status (200) to the client (VC), if this is not done, it will begin to flood with requests that lead to an error. While there is an idea about multithreading:
@app.route('/', methods = ['POST']) def mpage(): decoded = request.get_json() text = obj["body"] inp = list(text.split(sep=' ')) thread = Thread(target=seps, args=inp) thread.start() thread.join() return 'ok',200 def task(inp): #Задача But at startup, an error appears:
self._target(*self._args, **self._kwargs) TypeError: task() takes 1 positional argument but 2 were given When the error began to appear, I realized that something was wrong. In general, please help with the problem (Do not solve the error, although if that is the only correct solution to the problem, then it will also work)
TypeError, then solve problems further, for examplethread.join()blocks the current thread. To create for each request, the new thread is most likely not needed. You can try a pool of threads to usepool.submit(func, *args), where the pool is created only once when starting the servicepool = ThreadPoolExecutor(max_workers=20)(if you start using gunicorn, you can create a poolon_starting). Use the simplest solution that works. In a more general case, see Celery . - jfs