potiuk commented on issue #22404:
URL: https://github.com/apache/airflow/issues/22404#issuecomment-1074141785
> This happens when you raise the exception _outside_ the block? I can sort
of understand if you do it inside, but the temporary directory should be
deleted when the context manager exits. It is indeed strange if this is the
case.
Just to clarify - the `context manager` case behaves as expected (directory
deleted). The original one does not (i.e. the folder remains after Exception is
thrown and even after scheduler interpreter is stopped:
```python
import os
import tempfile
from airflow.decorators import dag, task
from airflow.utils.dates import days_ago
class MyException(Exception):
pass
@task
def run():
tmpdir = tempfile.TemporaryDirectory()
print(f"directory {tmpdir.name} created")
assert os.path.exists(tmpdir.name)
raise MyException("error!")
@dag(start_date=days_ago(1))
def tempfile_test():
run()
_ = tempfile_test()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]