Skip to content

Commit 42592cc

Browse files
authored
Merge pull request #94989 from ggailey777/crs-functions-temp-dir
Adding guidance for using tmp directory in Python
2 parents 45e71ba + 68a7930 commit 42592cc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

articles/azure-functions/functions-reference-python.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,27 @@ class TestFunction(unittest.TestCase):
529529
'msg body: test',
530530
)
531531
```
532+
## Temporary files
533+
534+
The `tempfile.gettempdir()` method returns a temporary folder, which on Linux is `/tmp`. Your application can use this directory to store temporary files generated and used by your functions during execution.
535+
536+
> [!IMPORTANT]
537+
> Files written to the temporary directory aren't guaranteed to persist across invocations. During scale out, temporary files aren't shared between instances.
538+
539+
The following example creates a named temporary file in the temporary directory (`/tmp`):
540+
541+
```python
542+
import logging
543+
import azure.functions as func
544+
import tempfile
545+
from os import listdir
546+
547+
#---
548+
tempFilePath = tempfile.gettempdir()
549+
fp = tempfile.NamedTemporaryFile()
550+
fp.write(b'Hello world!')
551+
filesDirListInTemp = listdir(tempFilePath)
552+
```
532553

533554
## Known issues and FAQ
534555

0 commit comments

Comments
 (0)