question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crashes with ValueError: I/O operation on closed file

See original GitHub issue

Hi there,

I have been using Concurrent log handler for few of my projects. One of them started to crash recently. Currently i tried the latest available version 0.9.12 without luck. Here is backtrace:

Traceback (most recent call last): File “/usr/lib/python3.6/logging/init.py”, line 996, in emit stream.write(msg) ValueError: I/O operation on closed file.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/core/handlers/exception.py”, line 34, in inner response = get_response(request) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/core/handlers/base.py”, line 126, in _get_response response = self.process_exception_by_middleware(e, request) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/core/handlers/base.py”, line 124, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/options.py”, line 607, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/utils/decorators.py”, line 142, in _wrapped_view response = view_func(request, *args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/views/decorators/cache.py”, line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/sites.py”, line 223, in inner return view(request, *args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/options.py”, line 1650, in change_view return self.changeform_view(request, object_id, form_url, extra_context) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/utils/decorators.py”, line 45, in _wrapper return bound_method(*args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/utils/decorators.py”, line 142, in _wrapped_view response = view_func(request, *args, **kwargs) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/options.py”, line 1536, in changeform_view return self._changeform_view(request, object_id, form_url, extra_context) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/options.py”, line 1575, in _changeform_view self.save_model(request, new_object, form, not add) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/contrib/admin/options.py”, line 1094, in save_model obj.save() File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/db/models/base.py”, line 717, in save force_update=force_update, update_fields=update_fields) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/db/models/base.py”, line 757, in save_base update_fields=update_fields, raw=raw, using=using, File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py”, line 175, in send for receiver in self._live_receivers(sender) File “/home/dismine/www/project/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py”, line 175, in <listcomp> for receiver in self._live_receivers(sender) File “/home/dismine/www/project/apps/backbone/signals.py”, line 13, in update_orders logger.debug(“Update orders signal”) File “/usr/lib/python3.6/logging/init.py”, line 1296, in debug self._log(DEBUG, msg, args, **kwargs) File “/usr/lib/python3.6/logging/init.py”, line 1444, in _log self.handle(record) File “/usr/lib/python3.6/logging/init.py”, line 1454, in handle self.callHandlers(record) File “/usr/lib/python3.6/logging/init.py”, line 1516, in callHandlers hdlr.handle(record) File “/usr/lib/python3.6/logging/init.py”, line 865, in handle self.emit(record) File “/usr/lib/python3.6/logging/init.py”, line 1000, in emit self.handleError(record) File “/usr/lib/python3.6/logging/init.py”, line 917, in handleError sys.stderr.write(‘— Logging error —\n’) ValueError: I/O operation on closed file.

I tried to understand what is wrong. It seems that something changed since 0.9.7. This is the last version that works for me. When i run command python manage.py runserver i get a lot of messages Unhandled exception in thread started by. As you can see this message is not very informative because no backtrace or name of function. Also log is empty. Normally i must see in console a lot debug messages, but not with the version above 0.9.7. The website kind of working. But when i try to save something it crashes with above log errors.

Place “/home/dismine/www/project/apps/backbone/signals.py” looks like this:

@receiver(post_save, sender=Customer)
def update_orders(sender, instance, **kwargs):
    logger = logging.getLogger(__name__)
    logger.debug("Update orders signal")
    if os.name != 'nt':
        restore_orders.apply_async((instance.pk, instance.measurements.pk), timeout=settings.RESTORING_ORDERS)

For now i will return to 0.9.7. If you need more info please tell me.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:32 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
disminecommented, Apr 29, 2019

Hi, i just tried and it works for me. Good job! Thank you.

1reaction
wkootcommented, May 3, 2019

Yep, also works for me on 3.4, 3.5, 3.6, 3.7 and 2.7. Thought I’d run through them all just to be sure

Read more comments on GitHub >

github_iconTop Results From Across the Web

[tune] Crash with ValueError: I/O operation on closed file #4744
The original ValueError: I/O operation on closed file might actually not be the actual cause of the failure, but just some error that...
Read more >
ValueError: I/O operation on closed file. [closed] - Stack Overflow
Your code snippet clearly shows that infile.close() operation is inside a loop, so it's executed on first iteration. Second read from file ......
Read more >
ValueError: I/O operation on closed file. in ZipFile destructor
The ZipFile destructor tries to close the BytesIO object, but it is already closed in its destructor.
Read more >
What causes 'ValueError: I/O operation on closed file' in Python?
Attempting to read a file handle that's been closed won't work. Thought that was what the problem was and tried it in the...
Read more >
Python ValueError: I/O operation on closed file Solution
Python ValueError: I/O operation on closed file Solution ... You can only read from and write to a Python file if the file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found