temporary-files

Temporary file with specific file extension in Python 3

对着背影说爱祢 提交于 2019-12-03 23:58:53
问题 I am writing some unit tests for a piece of code that takes a path and attempts to load the file if it has a known extension, then does more careful checking. In the unit test, I would like to create a temporary file that has the correct extension, but incorrect contents, in my case an empty file posing as test.tif . How can I create a temporary file while specifying the extension (or the entire name), using the tempfile module? I have looked at the NamedTemporaryFile class, as well as the

Real file objects slower than StringIO and cStringIO?

点点圈 提交于 2019-12-03 22:17:15
StringIO has the following notes in its code: Notes: - Using a real file is often faster (but less convenient). - There's also a much faster implementation in C, called cStringIO, but it's not subclassable. The "real file is often faster" line seemed really odd to me: how could writing to disk beat writing to memory? I tried profiling these different cases and got results that contradict these docs, as well as the answer to this question . This other question does explain why cStringIO is slower under some circumstances, though I'm not doing any concatenating here. The test writes a given

Python: How do I make temporary files in my test suite?

旧巷老猫 提交于 2019-12-03 22:14:35
(I'm using Python 2.6 and nose .) I'm writing tests for my Python app. I want one test to open a new file, close it, and then delete it. Naturally, I prefer that this will happen inside a temporary directory, because I don't want to trash the user's filesystem. And, it needs to be cross-OS. How do I do it? See the tempfile module in the standard library -- should be all you need. FWIW using py.test you can write: def test_function(tmpdir): # tmpdir is a unique-per-test-function invocation temporary directory Each test function using the "tmpdir" function argument will get a clean empty

How guarantee the file will be deleted after automatically some time? [closed]

喜夏-厌秋 提交于 2019-12-03 17:34:23
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 2 years ago . I have to store an image for a few minutes after user upload it until user confirm and i store in database So i'm wondering of creating a temporary file and use it to display preview. But I have to be sure that the file will be deleted after some time if user not interact anymore I found this article about temporary files and how delete them automatically https:/

Do files created with Path.GetTempFileName get cleaned up automatically?

独自空忆成欢 提交于 2019-12-03 14:57:10
问题 I've always assumed the answer is yes, but now I'm trying to find the truth. When I create a temp file using Path.GetTempFileName() , will windows automatically clean that up later? What about if I create a directory under Path.GetTempPath() ? Will windows clean it up? Or is it the developer's responsibility to delete files created there? 回答1: No they do not get deleted automatically. In order to create a file that will be deleted automatically when it is closed, pass FILE_FLAG_DELETE_ON

Can't delete temporary files after returning FileStream

别来无恙 提交于 2019-12-03 14:11:45
I have a function in a C# MVC application that creates a temporary directory and a temporary file, then opens the file using FileStream, returns the FileStream to a calling function, and then needs to delete the temporary files. However, I do not know how to delete the temp directory and file because it always errors out saying "the process cannot access the file because it is being used by another process." This is what I tried, but the FileStream is still using the temp file in the finally block. How can I return the FileStream and delete the temporary files? public FileStream

How to create a temporary file with portable shell in a secure way?

南笙酒味 提交于 2019-12-03 12:46:24
I want to create a temporary file in POSIX shell ( /bin/sh ). I found out that mktemp(1) doens't exist on my AIX box, and according to How portable is mktemp(1)? , it isn't that portable and/or secure anyway. So, what should I use instead ? billhill00 Why not use /dev/random ? It could be neater with perl but od and awk will do, something like: tempfile=XXX-$(od -N4 -tu /dev/random | awk 'NR==1 {print $2} {}') ghoti You didn't exactly define "secure", but one element of it is probably to clean up after yourself. trap "rm -f \"$tmpfile\"" 0 1 2 3 15 You can probably man 3 signal to see if there

How can I copy a file content into a temporary file in PHP? [duplicate]

若如初见. 提交于 2019-12-03 12:24:12
This question already has answers here : How to get a temporary file path? (5 answers) I tried this: $temp = tmpfile(); file_put_contents($temp,file_get_contents("$path/$filename")); But I get this error: "Warning: file_put_contents() expects parameter 1 to be string," If I try: echo file_get_contents("$path/$filename"); It return to screen the file content as a long string. Where am I wrong? tmpfile() creates a temporary file with a unique name in read-write (w+) mode and returns a file handle to use with fwrite for example. $temp = tmpfile(); fwrite($temp, file_get_contents("$path/$filename"

what is /tmp directory in hadoop hdfs?

a 夏天 提交于 2019-12-03 09:19:30
问题 I have cluster of 4 datanodes and hdfs structure on each node is as below I am facing disk space issue , as you can see the /tmp folder from hdfs has occupied more space(217GB). So i tried to investigate the data from /tmp folder. I found following temp files. I accessed these temp folders each contains some part files of 10gb to 20 gb in size. I want to clear this /tmp directory. can anyone please let me know the consequences of deleting these tmp folders or part files. Will it affect my

Deleting Temporary Files after usage

不打扰是莪最后的温柔 提交于 2019-12-03 07:24:45
问题 I need to work with some temporary files in my Windows Forms .NET 3.5 application. Those files are opened in an external application that can of course be running for a longer time than my own program. Are there any best practices to make sure these temporary files are cleaned up at any time in order to avoid filling the user's hard disk with "junk" files which aren't needed anymore? Or does even Windows kind of handle this automatically? A nice example is any mail client: When you open an