Repository: joblib/joblib
Pull request #1424 (2023-04-14 19:07:51)

DBG try to debug the thread_bomb_mitigation test
Investigation PR for #1150 

From the investigation, this bug seems to be related to a bad interaction between the test, Pypy and `coverage`.
I propose to disable the coverage on this test to stabilize the test suite.

I was able to reproduce the failure locally by running the test with `--cov=joblib` and by adding the following at the beginning of the test:
```python

def test_thread_bomb_mitigation(backend):
    def recursive():
        return recursive()
    with raises(RecursionError):
        recursive()
```
This could be investigated further if someone has the time to do so.

codecov[bot]: ## [Codecov](https://codecov.io/gh/joblib/joblib/pull/1424?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib) Report
Patch coverage has no change and project coverage change: **`-51.96`** :warning:
> Comparison is base [(`60ec53d`)](https://codecov.io/gh/joblib/joblib/commit/60ec53df7bd045373ba2db859b2a5f39b2f19b57?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib) 94.71% compared to head [(`6c30d9b`)](https://codecov.io/gh/joblib/joblib/pull/1424?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib) 42.76%.

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##           master    #1424       +/-   ##
===========================================
- Coverage   94.71%   42.76%   -51.96%     
===========================================
  Files          45       45               
  Lines        6890     6889        -1     
===========================================
- Hits         6526     2946     -3580     
- Misses        364     3943     +3579     
```


| [Impacted Files](https://codecov.io/gh/joblib/joblib/pull/1424?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib) | Coverage Δ | |
|---|---|---|
| [joblib/test/test\_parallel.py](https://codecov.io/gh/joblib/joblib/pull/1424?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib#diff-am9ibGliL3Rlc3QvdGVzdF9wYXJhbGxlbC5weQ==) | `31.70% <ø> (-65.44%)` | :arrow_down: |

... and [41 files with indirect coverage changes](https://codecov.io/gh/joblib/joblib/pull/1424/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib)

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib)

</details>

[:umbrella: View full report in Codecov by Sentry](https://codecov.io/gh/joblib/joblib/pull/1424?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=joblib).


Patch:
diff --git a/joblib/logger.py b/joblib/logger.py
index d5230b4..150c1e4 100644
--- a/joblib/logger.py
+++ b/joblib/logger.py
@@ -76,6 +76,9 @@ class Logger(object):
     def warn(self, msg):
         logging.warning("[%s]: %s" % (self, msg))
 
+    def info(self, msg):
+        logging.info("[%s]: %s" % (self, msg))
+
     def debug(self, msg):
         # XXX: This conflicts with the debug flag used in children class
         logging.debug("[%s]: %s" % (self, msg))
diff --git a/joblib/memory.py b/joblib/memory.py
index 806427d..90fe41e 100644
--- a/joblib/memory.py
+++ b/joblib/memory.py
@@ -10,7 +10,9 @@ is called with the same input arguments.
 
 
 from __future__ import with_statement
+import logging
 import os
+from textwrap import dedent
 import time
 import pathlib
 import pydoc
@@ -491,6 +493,26 @@ class MemorizedFunc(Logger):
         # Whether or not the memorized function must be called
         must_call = False
 
+        if self._verbose >= 20:
+            logging.basicConfig(level=logging.INFO)
+            _, name = get_func_name(self.func)
+            location = self.store_backend.get_cached_func_info([func_id])[
+                'location']
+            _, signature = format_signature(self.func, *args, **kwargs)
+
+            self.info(
+                dedent(
+                    f"""
+                        Querying {name} with signature
+                        {signature}.
+
+                        (argument hash {args_id})
+
+                        The store location is {location}.
+                        """
+                )
+            )
+
         # FIXME: The statements below should be try/excepted
         # Compare the function code with the previous to see if the
         # function code has changed


Test patch:
diff --git a/joblib/test/test_logger.py b/joblib/test/test_logger.py
index ad5204f..7cc59d4 100644
--- a/joblib/test/test_logger.py
+++ b/joblib/test/test_logger.py
@@ -5,7 +5,6 @@ Test the logger module.
 # Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
 # Copyright (c) 2009 Gael Varoquaux
 # License: BSD Style, 3 clauses.
-
 import re
 
 from joblib.logger import PrintTime
diff --git a/joblib/test/test_memory.py b/joblib/test/test_memory.py
index 72d4388..035e9a1 100644
--- a/joblib/test/test_memory.py
+++ b/joblib/test/test_memory.py
@@ -8,6 +8,7 @@ Test the memory module.
 
 import functools
 import gc
+import logging
 import shutil
 import os
 import os.path
@@ -1309,3 +1310,28 @@ def test_memory_pickle_dump_load(tmpdir, memory_kwargs):
     compare(memorized_result, memorized_result_reloaded,
             ignored_attrs=set(['store_backend', 'timestamp', '_func_code_id']))
     assert hash(memorized_result) == hash(memorized_result_reloaded)
+
+
+def test_info_log(tmpdir, caplog):
+    caplog.set_level(logging.INFO)
+    x = 3
+
+    memory = Memory(location=tmpdir.strpath, verbose=20)
+
+    @memory.cache
+    def f(x):
+        return x ** 2
+
+    _ = f(x)
+    assert "Querying" in caplog.text
+    caplog.clear()
+
+    memory = Memory(location=tmpdir.strpath, verbose=0)
+
+    @memory.cache
+    def f(x):
+        return x ** 2
+
+    _ = f(x)
+    assert "Querying" not in caplog.text
+    caplog.clear()
diff --git a/joblib/test/test_parallel.py b/joblib/test/test_parallel.py
index e8345c5..81ab7aa 100644
--- a/joblib/test/test_parallel.py
+++ b/joblib/test/test_parallel.py
@@ -1466,13 +1466,9 @@ def _recursive_parallel(nesting_limit=None):
 
 
 @parametrize(
-        'backend', (['threading'] if mp is None else ['loky', 'threading'])
-)
-# XXX: unskip once issue #1150 is closed.
-@skipif(
-    hasattr(sys, "pypy_version_info"),
-    reason="this test causes a deadlock on PyPy."
+    'backend', (['threading'] if mp is None else ['loky', 'threading'])
 )
+@pytest.mark.no_cover
 def test_thread_bomb_mitigation(backend):
     # Test that recursive parallelism raises a recursion rather than
     # saturating the operating system resources by creating a unbounded number
@@ -1493,8 +1489,8 @@ def test_thread_bomb_mitigation(backend):
             # simple to do and this is is not critical for users (as long
             # as there is no process or thread bomb happening).
             pytest.xfail("Loky worker crash when serializing RecursionError")
-    else:
-        assert isinstance(exc, RecursionError)
+
+    assert isinstance(exc, RecursionError)
 
 
 def _run_parallel_sum():