I'm using Prefect 3.1.4 and I'm still seeing the <...
# ask-community
j
I'm using Prefect 3.1.4 and I'm still seeing the problem of ValueError when the test harness is torn down. That bug is marked closed with 3.0.0rc10. Anyone else have this problem? The specific seems to be that when the test throws an exceptions.
n
hey @Joe - do you have a minimal example to reproduce?
j
It happens when one of the task throws an exception that is not caught by the test.
Is that expected behavior?
n
it sounds like it might be, but do you have the stack trace?
j
Copy code
-- Logging error ---
Traceback (most recent call last):
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/prefect/logging/handlers.py", line 319, in emit
    self.console.print(message, soft_wrap=True)
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/rich/console.py", line 1678, in print
    with self:
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/rich/console.py", line 864, in __exit__
    self._exit_buffer()
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/rich/console.py", line 822, in _exit_buffer
    self._check_buffer()
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/rich/console.py", line 2019, in _check_buffer
    self._write_buffer()
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/rich/console.py", line 2088, in _write_buffer
    self.file.write(text)
ValueError: I/O operation on closed file.
Call stack:
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/prefect/server/api/server.py", line 859, in stop
    <http://subprocess_server_logger.info|subprocess_server_logger.info>(
  File "/Users/joe/.asdf/installs/python/3.12.4/lib/python3.12/logging/__init__.py", line 1539, in info
    self._log(INFO, msg, args, **kwargs)
  File "/Users/joe/.asdf/installs/python/3.12.4/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/Users/joe/.asdf/installs/python/3.12.4/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/Users/joe/.asdf/installs/python/3.12.4/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/Users/joe/.asdf/installs/python/3.12.4/lib/python3.12/logging/__init__.py", line 1028, in handle
    self.emit(record)
  File "/Users/joe/Library/Caches/pypoetry/virtualenvs/feature-library-5-bR7ZDt-py3.12/lib/python3.12/site-packages/prefect/logging/handlers.py", line 325, in emit
    self.handleError(record)
Message: 'Stopping temporary server on <http://127.0.0.1:8485>'
OK, I can get that to stop if I wrap it in pytest.raises()
👍 1
n
gotcha, yeah I think this is not an error so much as a "weird background logging race condition" that we should still probably clean up at some point, but shouldnt affect user code at all
Copy code
py3.12/lib/python3.12/site-packages/rich/console.py", line 2088, in _write_buffer
    self.file.write(text)
ValueError: I/O operation on closed file.
j
So may be it is because when exception is thrown, the harness itself is not ready to catch.
n
its almost like the rich console dies before we have the chance to write our last log records
j
Tear down is tricky
n
hrm. if you want to open an issue about this, it would be appreciated for tracking!
otherwise I can do that later
j
ok
🙏 1