Skip to content
Advertisement

Tornado: how to close file object if exception/error in data_received when streaming chunked data to file

I am running Tornado with stream_request_body and saving a file POST request to file on server. In prepare I create the file object and in post I close file object. How do I capture any error/exception in data_received so that I can close the file object properly?

JavaScript

terminal output where tornado app is running

JavaScript

terminal output with python interpreter for the request

JavaScript

Advertisement

Answer

RequestHandler has an on_connection_close method which is called when a connection is closed. You can override this to close the file object:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement