flozz / yoga-image-optimizer

A graphical tool to convert and optimize JPEG, PNG and WebP images (based on YOGA)
https://yoga.flozz.org
GNU General Public License v3.0
144 stars 11 forks source link

[JPG-optimisation] - OSError: [Errno 9] Mauvais descripteur de fichier #12

Closed Amiralgaby closed 3 years ago

Amiralgaby commented 3 years ago

Hi Flozz,

Bug description

Exception in thread QueueManagerThread:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 376, in _queue_management_worker
    thread_wakeup.clear()
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 94, in clear
    self._reader.recv_bytes()
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 379, in _recv
    chunk = read(handle, remaining)
OSError: [Errno 9] Mauvais descripteur de fichier

What happened

An exception as been raised.

What was expected

No exception.

Step to reproduce

Steps to reproduce: I have chosen an image in JPG format, start the optimization process. When the optimization finished, an exception was thrown.

System information

flozz commented 3 years ago

Hello,

I tried to reproduce latest master revision with various Python versions, here are the results:

I will try to figure out what happens, thank you very much for your report! :+1:

flozz commented 3 years ago

I thought I was not able to reproduce anymore but it not reproducible every time (and I had the bug with PNGs too)... It looks like a race condition with concurrent.futures or multiprocessing...

I also had various stack traces:

Exception in thread QueueManagerThread:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 376, in _queue_management_worker
    thread_wakeup.clear()
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 93, in clear
    while self._reader.poll():
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 255, in poll
    self._check_closed()
  File "/usr/lib/python3.8/multiprocessing/connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed
Exception in thread QueueManagerThread:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 441, in _queue_management_worker
    shutdown_worker()
  File "/usr/lib/python3.8/concurrent/futures/process.py", line 334, in shutdown_worker
    call_queue.put_nowait(None)
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 132, in put_nowait
    return self.put(obj, False)
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 82, in put
    raise ValueError(f"Queue {self!r} is closed")
ValueError: Queue <concurrent.futures.process._SafeQueue object at 0x7f9e642f1ac0> is closed
flozz commented 3 years ago

It seems to be this bug, that has been fixed in Python 3.9: https://bugs.python.org/issue39995

In my tests, YOGA was able to generate the output image despite the exception displayed in the console. Can you confirm that it works the same for you?

flozz commented 3 years ago

This bug is located in Python itself, and is fixed in Python 3.9. As it is not blocking for using YOGA (only error displayed on console, but image optimized anyway), there no need for a workaround, so I close the issue.

Thank you for reporting it! :)