We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
travis has random failures on rank filters
## Description

See for ex: https://travis-ci.org/scikit-image/scikit-image/jobs/563363217


## Way to reproduce
```python
# Place the full code we need to recreate your issue here
# upload all necessary images to github too!
```


## Version information
```python
# Paste the output of the following python commands
from __future__ import print_function
import sys; print(sys.version)
import platform; print(platform.platform())
import skimage; print("scikit-image version: {}".format(skimage.__version__))
import numpy; print("numpy version: {}".format(numpy.__version__))
```

```python
# your output here

```



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `skimage/_shared/_warnings.py`
Content:
```
1 from contextlib import contextmanager
2 import sys
3 import warnings
4 import re
5 import os
6 
7 __all__ = ['all_warnings', 'expected_warnings', 'warn']
8 
9 
10 def warn(message, category=None, stacklevel=2):
11     """A version of `warnings.warn` with a default stacklevel of 2.
12     """
13     if category is not None:
14         warnings.warn(message, category=category, stacklevel=stacklevel)
15     else:
16         warnings.warn(message, stacklevel=stacklevel)
17 
18 
19 @contextmanager
20 def all_warnings():
21     """
22     Context for use in testing to ensure that all warnings are raised.
23 
24     Examples
25     --------
26     >>> import warnings
27     >>> def foo():
28     ...     warnings.warn(RuntimeWarning("bar"))
29 
30     We raise the warning once, while the warning filter is set to "once".
31     Hereafter, the warning is invisible, even with custom filters:
32 
33     >>> with warnings.catch_warnings():
34     ...     warnings.simplefilter('once')
35     ...     foo()
36 
37     We can now run ``foo()`` without a warning being raised:
38 
39     >>> from numpy.testing import assert_warns
40     >>> foo()
41 
42     To catch the warning, we call in the help of ``all_warnings``:
43 
44     >>> with all_warnings():
45     ...     assert_warns(RuntimeWarning, foo)
46     """
47     # _warnings.py is on the critical import path.
48     # Since this is a testing only function, we lazy import inspect.
49     import inspect
50     # Whenever a warning is triggered, Python adds a __warningregistry__
51     # member to the *calling* module.  The exercize here is to find
52     # and eradicate all those breadcrumbs that were left lying around.
53     #
54     # We proceed by first searching all parent calling frames and explicitly
55     # clearing their warning registries (necessary for the doctests above to
56     # pass).  Then, we search for all submodules of skimage and clear theirs
57     # as well (necessary for the skimage test suite to pass).
58 
59     frame = inspect.currentframe()
60     if frame:
61         for f in inspect.getouterframes(frame):
62             f[0].f_locals['__warningregistry__'] = {}
63     del frame
64 
65     for mod_name, mod in list(sys.modules.items()):
66         try:
67             mod.__warningregistry__.clear()
68         except AttributeError:
69             pass
70 
71     with warnings.catch_warnings(record=True) as w:
72         warnings.simplefilter("always")
73         yield w
74 
75 
76 @contextmanager
77 def expected_warnings(matching):
78     r"""Context for use in testing to catch known warnings matching regexes
79 
80     Parameters
81     ----------
82     matching : list of strings or compiled regexes
83         Regexes for the desired warning to catch
84 
85     Examples
86     --------
87     >>> import numpy as np
88     >>> image = np.random.randint(0, 2**16, size=(100, 100), dtype=np.uint16)
89     >>> # rank filters are slow when bit-depth exceeds 10 bits
90     >>> from skimage import filters
91     >>> with expected_warnings(['Bad rank filter performance']):
92     ...     median_filtered = filters.rank.median(image)
93 
94     Notes
95     -----
96     Uses `all_warnings` to ensure all warnings are raised.
97     Upon exiting, it checks the recorded warnings for the desired matching
98     pattern(s).
99     Raises a ValueError if any match was not found or an unexpected
100     warning was raised.
101     Allows for three types of behaviors: `and`, `or`, and `optional` matches.
102     This is done to accommodate different build environments or loop conditions
103     that may produce different warnings.  The behaviors can be combined.
104     If you pass multiple patterns, you get an orderless `and`, where all of the
105     warnings must be raised.
106     If you use the `|` operator in a pattern, you can catch one of several
107     warnings.
108     Finally, you can use `|\A\Z` in a pattern to signify it as optional.
109 
110     """
111     if isinstance(matching, str):
112         raise ValueError('``matching`` should be a list of strings and not '
113                          'a string itself.')
114 
115     strict_warnings = os.environ.get('SKIMAGE_TEST_STRICT_WARNINGS', '1')
116     if strict_warnings.lower() == 'true':
117         strict_warnings = True
118     elif strict_warnings.lower() == 'false':
119         strict_warnings = False
120     else:
121         strict_warnings = bool(int(strict_warnings))
122 
123     with all_warnings() as w:
124         # enter context
125         yield w
126         # exited user context, check the recorded warnings
127         # Allow users to provide None
128         while None in matching:
129             matching.remove(None)
130         remaining = [m for m in matching if r'\A\Z' not in m.split('|')]
131         for warn in w:
132             found = False
133             for match in matching:
134                 if re.search(match, str(warn.message)) is not None:
135                     found = True
136                     if match in remaining:
137                         remaining.remove(match)
138             if strict_warnings and not found:
139                 raise ValueError('Unexpected warning: %s' % str(warn.message))
140         if strict_warnings and (len(remaining) > 0):
141             msg = 'No warning raised matching:\n%s' % '\n'.join(remaining)
142             raise ValueError(msg)
143
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py
--- a/skimage/_shared/_warnings.py
+++ b/skimage/_shared/_warnings.py
@@ -79,8 +79,9 @@
 
     Parameters
     ----------
-    matching : list of strings or compiled regexes
+    matching : None or a list of strings or compiled regexes
         Regexes for the desired warning to catch
+        If matching is None, this behaves as a no-op.
 
     Examples
     --------
@@ -112,6 +113,11 @@
         raise ValueError('``matching`` should be a list of strings and not '
                          'a string itself.')
 
+    # Special case for disabling the context manager
+    if matching is None:
+        yield None
+        return
+
     strict_warnings = os.environ.get('SKIMAGE_TEST_STRICT_WARNINGS', '1')
     if strict_warnings.lower() == 'true':
         strict_warnings = True

{"golden_diff": "diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py\n--- a/skimage/_shared/_warnings.py\n+++ b/skimage/_shared/_warnings.py\n@@ -79,8 +79,9 @@\n \n     Parameters\n     ----------\n-    matching : list of strings or compiled regexes\n+    matching : None or a list of strings or compiled regexes\n         Regexes for the desired warning to catch\n+        If matching is None, this behaves as a no-op.\n \n     Examples\n     --------\n@@ -112,6 +113,11 @@\n         raise ValueError('``matching`` should be a list of strings and not '\n                          'a string itself.')\n \n+    # Special case for disabling the context manager\n+    if matching is None:\n+        yield None\n+        return\n+\n     strict_warnings = os.environ.get('SKIMAGE_TEST_STRICT_WARNINGS', '1')\n     if strict_warnings.lower() == 'true':\n         strict_warnings = True\n", "issue": "travis has random failures on rank filters\n## Description\r\n\r\nSee for ex: https://travis-ci.org/scikit-image/scikit-image/jobs/563363217\r\n\r\n\r\n## Way to reproduce\r\n```python\r\n# Place the full code we need to recreate your issue here\r\n# upload all necessary images to github too!\r\n```\r\n\r\n\r\n## Version information\r\n```python\r\n# Paste the output of the following python commands\r\nfrom __future__ import print_function\r\nimport sys; print(sys.version)\r\nimport platform; print(platform.platform())\r\nimport skimage; print(\"scikit-image version: {}\".format(skimage.__version__))\r\nimport numpy; print(\"numpy version: {}\".format(numpy.__version__))\r\n```\r\n\r\n```python\r\n# your output here\r\n\r\n```\r\n\r\n\n", "before_files": [{"content": "from contextlib import contextmanager\nimport sys\nimport warnings\nimport re\nimport os\n\n__all__ = ['all_warnings', 'expected_warnings', 'warn']\n\n\ndef warn(message, category=None, stacklevel=2):\n    \"\"\"A version of `warnings.warn` with a default stacklevel of 2.\n    \"\"\"\n    if category is not None:\n        warnings.warn(message, category=category, stacklevel=stacklevel)\n    else:\n        warnings.warn(message, stacklevel=stacklevel)\n\n\n@contextmanager\ndef all_warnings():\n    \"\"\"\n    Context for use in testing to ensure that all warnings are raised.\n\n    Examples\n    --------\n    >>> import warnings\n    >>> def foo():\n    ...     warnings.warn(RuntimeWarning(\"bar\"))\n\n    We raise the warning once, while the warning filter is set to \"once\".\n    Hereafter, the warning is invisible, even with custom filters:\n\n    >>> with warnings.catch_warnings():\n    ...     warnings.simplefilter('once')\n    ...     foo()\n\n    We can now run ``foo()`` without a warning being raised:\n\n    >>> from numpy.testing import assert_warns\n    >>> foo()\n\n    To catch the warning, we call in the help of ``all_warnings``:\n\n    >>> with all_warnings():\n    ...     assert_warns(RuntimeWarning, foo)\n    \"\"\"\n    # _warnings.py is on the critical import path.\n    # Since this is a testing only function, we lazy import inspect.\n    import inspect\n    # Whenever a warning is triggered, Python adds a __warningregistry__\n    # member to the *calling* module.  The exercize here is to find\n    # and eradicate all those breadcrumbs that were left lying around.\n    #\n    # We proceed by first searching all parent calling frames and explicitly\n    # clearing their warning registries (necessary for the doctests above to\n    # pass).  Then, we search for all submodules of skimage and clear theirs\n    # as well (necessary for the skimage test suite to pass).\n\n    frame = inspect.currentframe()\n    if frame:\n        for f in inspect.getouterframes(frame):\n            f[0].f_locals['__warningregistry__'] = {}\n    del frame\n\n    for mod_name, mod in list(sys.modules.items()):\n        try:\n            mod.__warningregistry__.clear()\n        except AttributeError:\n            pass\n\n    with warnings.catch_warnings(record=True) as w:\n        warnings.simplefilter(\"always\")\n        yield w\n\n\n@contextmanager\ndef expected_warnings(matching):\n    r\"\"\"Context for use in testing to catch known warnings matching regexes\n\n    Parameters\n    ----------\n    matching : list of strings or compiled regexes\n        Regexes for the desired warning to catch\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> image = np.random.randint(0, 2**16, size=(100, 100), dtype=np.uint16)\n    >>> # rank filters are slow when bit-depth exceeds 10 bits\n    >>> from skimage import filters\n    >>> with expected_warnings(['Bad rank filter performance']):\n    ...     median_filtered = filters.rank.median(image)\n\n    Notes\n    -----\n    Uses `all_warnings` to ensure all warnings are raised.\n    Upon exiting, it checks the recorded warnings for the desired matching\n    pattern(s).\n    Raises a ValueError if any match was not found or an unexpected\n    warning was raised.\n    Allows for three types of behaviors: `and`, `or`, and `optional` matches.\n    This is done to accommodate different build environments or loop conditions\n    that may produce different warnings.  The behaviors can be combined.\n    If you pass multiple patterns, you get an orderless `and`, where all of the\n    warnings must be raised.\n    If you use the `|` operator in a pattern, you can catch one of several\n    warnings.\n    Finally, you can use `|\\A\\Z` in a pattern to signify it as optional.\n\n    \"\"\"\n    if isinstance(matching, str):\n        raise ValueError('``matching`` should be a list of strings and not '\n                         'a string itself.')\n\n    strict_warnings = os.environ.get('SKIMAGE_TEST_STRICT_WARNINGS', '1')\n    if strict_warnings.lower() == 'true':\n        strict_warnings = True\n    elif strict_warnings.lower() == 'false':\n        strict_warnings = False\n    else:\n        strict_warnings = bool(int(strict_warnings))\n\n    with all_warnings() as w:\n        # enter context\n        yield w\n        # exited user context, check the recorded warnings\n        # Allow users to provide None\n        while None in matching:\n            matching.remove(None)\n        remaining = [m for m in matching if r'\\A\\Z' not in m.split('|')]\n        for warn in w:\n            found = False\n            for match in matching:\n                if re.search(match, str(warn.message)) is not None:\n                    found = True\n                    if match in remaining:\n                        remaining.remove(match)\n            if strict_warnings and not found:\n                raise ValueError('Unexpected warning: %s' % str(warn.message))\n        if strict_warnings and (len(remaining) > 0):\n            msg = 'No warning raised matching:\\n%s' % '\\n'.join(remaining)\n            raise ValueError(msg)\n", "path": "skimage/_shared/_warnings.py"}], "after_files": [{"content": "from contextlib import contextmanager\nimport sys\nimport warnings\nimport re\nimport os\n\n__all__ = ['all_warnings', 'expected_warnings', 'warn']\n\n\ndef warn(message, category=None, stacklevel=2):\n    \"\"\"A version of `warnings.warn` with a default stacklevel of 2.\n    \"\"\"\n    if category is not None:\n        warnings.warn(message, category=category, stacklevel=stacklevel)\n    else:\n        warnings.warn(message, stacklevel=stacklevel)\n\n\n@contextmanager\ndef all_warnings():\n    \"\"\"\n    Context for use in testing to ensure that all warnings are raised.\n\n    Examples\n    --------\n    >>> import warnings\n    >>> def foo():\n    ...     warnings.warn(RuntimeWarning(\"bar\"))\n\n    We raise the warning once, while the warning filter is set to \"once\".\n    Hereafter, the warning is invisible, even with custom filters:\n\n    >>> with warnings.catch_warnings():\n    ...     warnings.simplefilter('once')\n    ...     foo()\n\n    We can now run ``foo()`` without a warning being raised:\n\n    >>> from numpy.testing import assert_warns\n    >>> foo()\n\n    To catch the warning, we call in the help of ``all_warnings``:\n\n    >>> with all_warnings():\n    ...     assert_warns(RuntimeWarning, foo)\n    \"\"\"\n    # _warnings.py is on the critical import path.\n    # Since this is a testing only function, we lazy import inspect.\n    import inspect\n    # Whenever a warning is triggered, Python adds a __warningregistry__\n    # member to the *calling* module.  The exercize here is to find\n    # and eradicate all those breadcrumbs that were left lying around.\n    #\n    # We proceed by first searching all parent calling frames and explicitly\n    # clearing their warning registries (necessary for the doctests above to\n    # pass).  Then, we search for all submodules of skimage and clear theirs\n    # as well (necessary for the skimage test suite to pass).\n\n    frame = inspect.currentframe()\n    if frame:\n        for f in inspect.getouterframes(frame):\n            f[0].f_locals['__warningregistry__'] = {}\n    del frame\n\n    for mod_name, mod in list(sys.modules.items()):\n        try:\n            mod.__warningregistry__.clear()\n        except AttributeError:\n            pass\n\n    with warnings.catch_warnings(record=True) as w:\n        warnings.simplefilter(\"always\")\n        yield w\n\n\n@contextmanager\ndef expected_warnings(matching):\n    r\"\"\"Context for use in testing to catch known warnings matching regexes\n\n    Parameters\n    ----------\n    matching : None or a list of strings or compiled regexes\n        Regexes for the desired warning to catch\n        If matching is None, this behaves as a no-op.\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> image = np.random.randint(0, 2**16, size=(100, 100), dtype=np.uint16)\n    >>> # rank filters are slow when bit-depth exceeds 10 bits\n    >>> from skimage import filters\n    >>> with expected_warnings(['Bad rank filter performance']):\n    ...     median_filtered = filters.rank.median(image)\n\n    Notes\n    -----\n    Uses `all_warnings` to ensure all warnings are raised.\n    Upon exiting, it checks the recorded warnings for the desired matching\n    pattern(s).\n    Raises a ValueError if any match was not found or an unexpected\n    warning was raised.\n    Allows for three types of behaviors: `and`, `or`, and `optional` matches.\n    This is done to accommodate different build environments or loop conditions\n    that may produce different warnings.  The behaviors can be combined.\n    If you pass multiple patterns, you get an orderless `and`, where all of the\n    warnings must be raised.\n    If you use the `|` operator in a pattern, you can catch one of several\n    warnings.\n    Finally, you can use `|\\A\\Z` in a pattern to signify it as optional.\n\n    \"\"\"\n    if isinstance(matching, str):\n        raise ValueError('``matching`` should be a list of strings and not '\n                         'a string itself.')\n\n    # Special case for disabling the context manager\n    if matching is None:\n        yield None\n        return\n\n    strict_warnings = os.environ.get('SKIMAGE_TEST_STRICT_WARNINGS', '1')\n    if strict_warnings.lower() == 'true':\n        strict_warnings = True\n    elif strict_warnings.lower() == 'false':\n        strict_warnings = False\n    else:\n        strict_warnings = bool(int(strict_warnings))\n\n    with all_warnings() as w:\n        # enter context\n        yield w\n        # exited user context, check the recorded warnings\n        # Allow users to provide None\n        while None in matching:\n            matching.remove(None)\n        remaining = [m for m in matching if r'\\A\\Z' not in m.split('|')]\n        for warn in w:\n            found = False\n            for match in matching:\n                if re.search(match, str(warn.message)) is not None:\n                    found = True\n                    if match in remaining:\n                        remaining.remove(match)\n            if strict_warnings and not found:\n                raise ValueError('Unexpected warning: %s' % str(warn.message))\n        if strict_warnings and (len(remaining) > 0):\n            msg = 'No warning raised matching:\\n%s' % '\\n'.join(remaining)\n            raise ValueError(msg)\n", "path": "skimage/_shared/_warnings.py"}]}