Problem with temporary files
Hi,I have a problem using the tempfile library on Spaces. This problem occurs sometimes.I havethisspace that generates an output file that is a disk write and the main function returns the path to this file.I know that if I do not use a tempfile, this works correctly, but I’d like to use tempfile to prevent generations of outputs in a local execution.Thisis the function that generates the problem (temporary file lines are commented out to avoid errors).And the logs when the execution fails are the following:Traceback (most recent call last):File “/home/user/.local/lib/python3.8/site-packages/gradio/routes.py”, line 259, in run_predictoutput = await app.blocks.process_api(File “/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py”, line 691, in process_apipredictions = self.postprocess_data(fn_index, predictions, state)File “/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py”, line 657, in postprocess_datablock.postprocess(prediction_value)File “/home/user/.local/lib/python3.8/site-packages/gradio/components.py”, line 1676, in postprocessy = processing_utils.create_tmp_copy_of_file(y, dir=self.temp_dir)File “/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py”, line 296, in create_tmp_copy_of_fileshutil.copy2(file_path, file_obj.name)File “/usr/local/lib/python3.8/shutil.py”, line 435, in copy2copyfile(src, dst, follow_symlinks=follow_symlinks)File “/usr/local/lib/python3.8/shutil.py”, line 264, in copyfilewith open(src, ‘rb’) as fsrc, open(dst, ‘wb’) as fdst:FileNotFoundError: [Errno 2] No such file or directory: ‘/tmp/tmpsp16mbfp/soccer532nbnksvotwvex0_out.mp4’As I mentioned earlier, this code runs perfectly in many situations, but sometimes finish with the above error.Any suggestions to use the tempfile library capabilities properly on Spaces?Thank you,Diego.
2022-09-15T18:57:14Z
Hi@diegofernandezc!You may have to copy your file into your temporary directory so that it doesn’t get deleted?I think it’s fine if your demo doesn’t create a temporary file. Gradio will do that under the hood for you when your output component isFile.
2023-12-27T07:13:50Z
I looked for this on various websites including youtube and solved it using to verify the temp folderpath.