errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 614 forks source link

Fix threading warnings for Python 3.8 and 3.9 in unit tests #1494

Closed nzlosh closed 3 years ago

nzlosh commented 3 years ago

In order to let us help you better, please fill out the following fields as best you can:

I am...

I am running...

Issue description

Unit tests running on Python 3.6 and 3.7 complete without warnings. The same unit tests run on Python 3.8 or Python 3.9 are returning exceptions:

=============================== warnings summary ===============================
tests/commands_test.py::test_backup
  /home/runner/work/errbot/errbot/.tox/py/lib/python3.9/site-packages/_pytest/threadexception.py:75: PytestUnhandledThreadExceptionWarning: Exception in thread TestBot main thread

  Traceback (most recent call last):
    File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/threading.py", line 954, in _bootstrap_inner
      self.run()
    File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/threading.py", line 892, in run
      self._target(*self._args, **self._kwargs)
    File "/home/runner/work/errbot/errbot/errbot/backends/test.py", line 298, in serve_forever
      self.shutdown()
    File "/home/runner/work/errbot/errbot/errbot/core.py", line 805, in shutdown
      self.close_storage()
    File "/home/runner/work/errbot/errbot/errbot/storage/__init__.py", line 39, in close_storage
      raise StoreNotOpenError("Storage does not appear to have been opened yet")
  errbot.storage.StoreNotOpenError: Storage does not appear to have been opened yet

    warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))

and

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================= 216 passed, 1 warning in 26.91s ========================
Exception ignored in: <function Pool.__del__ at 0x7f16c52cdca0>
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/pool.py", line 268, in __del__
    self._change_notifier.put(None)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/queues.py", line 378, in put
    self._writer.send_bytes(obj)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 205, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 416, in _send_bytes
    self._send(header + buf)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 373, in _send
    n = write(self._handle, buf)
OSError: [Errno 9] Bad file descriptor
Exception ignored in: <function Pool.__del__ at 0x7f16c52cdca0>
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/pool.py", line 268, in __del__
    self._change_notifier.put(None)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/queues.py", line 378, in put
    self._writer.send_bytes(obj)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 205, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 416, in _send_bytes
    self._send(header + buf)
  File "/opt/hostedtoolcache/Python/3.9.1/x64/lib/python3.9/multiprocessing/connection.py", line 373, in _send
    n = write(self._handle, buf)
OSError: [Errno 9] Bad file descriptor

This seems to suggest there have been threading changes between 3.7 and 3.8 that need to be taken into account.

Steps to reproduce

Run unit tests using Python 3.8 or Python 3.9

nzlosh commented 3 years ago

Closing, a fix has already been proposed here #1486