We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
signal handler can only be used in main thread
Often get these with conda-build tests

https://travis-ci.org/conda/conda/jobs/225296134#L1380

```
Traceback (most recent call last):
  File "/home/travis/build/conda/conda/conda-build/conda_build/build.py", line 688, in create_env
    execute_actions(actions, index, verbose=config.debug)
  File "/home/travis/build/conda/conda/conda/plan.py", line 612, in execute_actions
    execute_instructions(plan, index, verbose)
  File "/home/travis/build/conda/conda/conda/instructions.py", line 243, in execute_instructions
    cmd(state, arg)
  File "/home/travis/build/conda/conda/conda/instructions.py", line 98, in PROGRESSIVEFETCHEXTRACT_CMD
    progressive_fetch_extract.execute()
  File "/home/travis/build/conda/conda/conda/core/package_cache.py", line 491, in execute
    with signal_handler(conda_signal_handler):
  File "/home/travis/miniconda/lib/python3.6/contextlib.py", line 82, in __enter__
    return next(self.gen)
  File "/home/travis/build/conda/conda/conda/common/signals.py", line 41, in signal_handler
    prev_handler = signal.signal(sig, handler)
  File "/home/travis/miniconda/lib/python3.6/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
```
signal handler can only be used in main thread
Often get these with conda-build tests

https://travis-ci.org/conda/conda/jobs/225296134#L1380

```
Traceback (most recent call last):
  File "/home/travis/build/conda/conda/conda-build/conda_build/build.py", line 688, in create_env
    execute_actions(actions, index, verbose=config.debug)
  File "/home/travis/build/conda/conda/conda/plan.py", line 612, in execute_actions
    execute_instructions(plan, index, verbose)
  File "/home/travis/build/conda/conda/conda/instructions.py", line 243, in execute_instructions
    cmd(state, arg)
  File "/home/travis/build/conda/conda/conda/instructions.py", line 98, in PROGRESSIVEFETCHEXTRACT_CMD
    progressive_fetch_extract.execute()
  File "/home/travis/build/conda/conda/conda/core/package_cache.py", line 491, in execute
    with signal_handler(conda_signal_handler):
  File "/home/travis/miniconda/lib/python3.6/contextlib.py", line 82, in __enter__
    return next(self.gen)
  File "/home/travis/build/conda/conda/conda/common/signals.py", line 41, in signal_handler
    prev_handler = signal.signal(sig, handler)
  File "/home/travis/miniconda/lib/python3.6/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda/exports.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 
4 from functools import partial
5 from logging import getLogger
6 from warnings import warn
7 
8 log = getLogger(__name__)
9 
10 from . import CondaError  # NOQA
11 CondaError = CondaError
12 
13 from . import compat, plan  # NOQA
14 compat, plan = compat, plan
15 
16 from .api import get_index  # NOQA
17 get_index = get_index
18 
19 from .cli.common import specs_from_args, spec_from_line, specs_from_url  # NOQA
20 from .cli.conda_argparse import add_parser_prefix, add_parser_channels  # NOQA
21 add_parser_channels, add_parser_prefix = add_parser_channels, add_parser_prefix
22 specs_from_args, spec_from_line = specs_from_args, spec_from_line
23 specs_from_url = specs_from_url
24 
25 from .cli.conda_argparse import ArgumentParser  # NOQA
26 ArgumentParser = ArgumentParser
27 
28 from .common.compat import PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA
29 PY3, StringIO,  input, iteritems, string_types, text_type = PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA
30 from .gateways.connection import CondaSession  # NOQA
31 CondaSession = CondaSession
32 
33 from .common.toposort import _toposort
34 _toposort = _toposort
35 
36 from .gateways.disk.link import lchmod  # NOQA
37 lchmod = lchmod
38 
39 from .fetch import TmpDownload  # NOQA
40 TmpDownload = TmpDownload
41 handle_proxy_407 = lambda x, y: warn("handle_proxy_407 is deprecated. "
42                                      "Now handled by CondaSession.")
43 from .core.index import dist_str_in_index, fetch_index  # NOQA
44 dist_str_in_index, fetch_index = dist_str_in_index, fetch_index
45 from .core.package_cache import download, rm_fetched  # NOQA
46 download, rm_fetched = download, rm_fetched
47 
48 from .install import package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA
49 package_cache, prefix_placeholder, rm_rf, symlink_conda = package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA
50 
51 from .gateways.disk.delete import delete_trash, move_to_trash  # NOQA
52 delete_trash, move_to_trash = delete_trash, move_to_trash
53 
54 from .core.linked_data import is_linked, linked, linked_data  # NOQA
55 is_linked, linked, linked_data = is_linked, linked, linked_data
56 
57 from .misc import untracked, walk_prefix  # NOQA
58 untracked, walk_prefix = untracked, walk_prefix
59 
60 from .resolve import MatchSpec, NoPackagesFound, Resolve, Unsatisfiable, normalized_version  # NOQA
61 MatchSpec, NoPackagesFound, Resolve = MatchSpec, NoPackagesFound, Resolve
62 Unsatisfiable, normalized_version = Unsatisfiable, normalized_version
63 
64 from .signature import KEYS, KEYS_DIR, hash_file, verify  # NOQA
65 KEYS, KEYS_DIR = KEYS, KEYS_DIR
66 hash_file, verify = hash_file, verify
67 
68 from .utils import hashsum_file, human_bytes, memoized, unix_path_to_win, win_path_to_unix, url_path  # NOQA
69 hashsum_file, human_bytes = hashsum_file, human_bytes
70 memoized, unix_path_to_win = memoized, unix_path_to_win
71 win_path_to_unix, url_path = win_path_to_unix, url_path
72 
73 from .gateways.disk.read import compute_md5sum  # NOQA
74 md5_file = compute_md5sum
75 
76 from .config import sys_rc_path  # NOQA
77 sys_rc_path = sys_rc_path
78 
79 from .models.version import VersionOrder  # NOQA
80 VersionOrder = VersionOrder
81 
82 import conda.base.context  # NOQA
83 from .base.context import get_prefix as context_get_prefix, non_x86_linux_machines  # NOQA
84 non_x86_linux_machines = non_x86_linux_machines
85 
86 from ._vendor.auxlib.entity import EntityEncoder        # NOQA
87 EntityEncoder = EntityEncoder
88 from .base.constants import DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA
89 DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX = DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA
90 get_prefix = partial(context_get_prefix, conda.base.context.context)
91 get_default_urls = lambda: DEFAULT_CHANNELS
92 
93 arch_name = conda.base.context.context.arch_name
94 binstar_upload = conda.base.context.context.anaconda_upload
95 bits = conda.base.context.context.bits
96 default_prefix = conda.base.context.context.default_prefix
97 default_python = conda.base.context.context.default_python
98 envs_dirs = conda.base.context.context.envs_dirs
99 pkgs_dirs = conda.base.context.context.pkgs_dirs
100 platform = conda.base.context.context.platform
101 root_dir = conda.base.context.context.root_prefix
102 root_writable = conda.base.context.context.root_writable
103 subdir = conda.base.context.context.subdir
104 from .models.channel import get_conda_build_local_url  # NOQA
105 get_rc_urls = lambda: list(conda.base.context.context.channels)
106 get_local_urls = lambda: list(get_conda_build_local_url()) or []
107 load_condarc = lambda fn: conda.base.context.reset_context([fn])
108 from .exceptions import PaddingError  # NOQA
109 PaddingError = PaddingError
110 from .gateways.disk.link import CrossPlatformStLink  # NOQA
111 CrossPlatformStLink = CrossPlatformStLink
112 
113 from .models.enums import FileMode  # NOQA
114 FileMode = FileMode
115 from .models.enums import PathType  # NOQA
116 PathType = PathType
117 
118 
119 if PY3:
120     import configparser  # NOQA  # pragma: py2 no cover
121 else:
122     import ConfigParser as configparser  # NOQA  # pragma: py3 no cover
123 configparser = configparser
124 
125 
126 from .compat import TemporaryDirectory  # NOQA
127 TemporaryDirectory = TemporaryDirectory
128 
129 from .gateways.subprocess import ACTIVE_SUBPROCESSES, subprocess_call  # NOQA
130 ACTIVE_SUBPROCESSES, subprocess_call = ACTIVE_SUBPROCESSES, subprocess_call
131 
132 from .core.repodata import cache_fn_url  # NOQA
133 cache_fn_url = cache_fn_url
134 
135 
136 class Completer(object):
137     def get_items(self):
138         return self._get_items()
139 
140     def __contains__(self, item):
141         return True
142 
143     def __iter__(self):
144         return iter(self.get_items())
145 
146 class InstalledPackages(object): pass  # NOQA
147
```

Path: `conda/common/signals.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 
4 from contextlib import contextmanager
5 from logging import getLogger
6 import signal
7 
8 from .compat import iteritems
9 
10 log = getLogger(__name__)
11 
12 INTERRUPT_SIGNALS = (
13     'SIGABRT',
14     'SIGINT',
15     'SIGTERM',
16     'SIGQUIT',
17     'SIGBREAK',
18 )
19 
20 
21 def get_signal_name(signum):
22     """
23     Examples:
24         >>> from signal import SIGINT
25         >>> get_signal_name(SIGINT)
26         'SIGINT'
27 
28     """
29     return next((k for k, v in iteritems(signal.__dict__)
30                  if v == signum and k.startswith('SIG') and not k.startswith('SIG_')),
31                 None)
32 
33 
34 @contextmanager
35 def signal_handler(handler):
36     previous_handlers = []
37     for signame in INTERRUPT_SIGNALS:
38         sig = getattr(signal, signame, None)
39         if sig:
40             log.debug("registering handler for %s", signame)
41             prev_handler = signal.signal(sig, handler)
42             previous_handlers.append((sig, prev_handler))
43     try:
44         yield
45     finally:
46         standard_handlers = signal.SIG_IGN, signal.SIG_DFL
47         for sig, previous_handler in previous_handlers:
48             if callable(previous_handler) or previous_handler in standard_handlers:
49                 log.debug("de-registering handler for %s", sig)
50                 signal.signal(sig, previous_handler)
51
```
--- 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/conda/common/signals.py b/conda/common/signals.py
--- a/conda/common/signals.py
+++ b/conda/common/signals.py
@@ -4,6 +4,7 @@
 from contextlib import contextmanager
 from logging import getLogger
 import signal
+import threading
 
 from .compat import iteritems
 
@@ -17,7 +18,6 @@
     'SIGBREAK',
 )
 
-
 def get_signal_name(signum):
     """
     Examples:
@@ -33,18 +33,23 @@
 
 @contextmanager
 def signal_handler(handler):
-    previous_handlers = []
+    _thread_local = threading.local()
+    _thread_local.previous_handlers = []
     for signame in INTERRUPT_SIGNALS:
         sig = getattr(signal, signame, None)
         if sig:
             log.debug("registering handler for %s", signame)
-            prev_handler = signal.signal(sig, handler)
-            previous_handlers.append((sig, prev_handler))
+            try:
+                prev_handler = signal.signal(sig, handler)
+                _thread_local.previous_handlers.append((sig, prev_handler))
+            except ValueError as e:
+                # ValueError: signal only works in main thread
+                log.debug('%r', e)
     try:
         yield
     finally:
         standard_handlers = signal.SIG_IGN, signal.SIG_DFL
-        for sig, previous_handler in previous_handlers:
+        for sig, previous_handler in _thread_local.previous_handlers:
             if callable(previous_handler) or previous_handler in standard_handlers:
                 log.debug("de-registering handler for %s", sig)
                 signal.signal(sig, previous_handler)
diff --git a/conda/exports.py b/conda/exports.py
--- a/conda/exports.py
+++ b/conda/exports.py
@@ -30,7 +30,7 @@
 from .gateways.connection import CondaSession  # NOQA
 CondaSession = CondaSession
 
-from .common.toposort import _toposort
+from .common.toposort import _toposort  # NOQA
 _toposort = _toposort
 
 from .gateways.disk.link import lchmod  # NOQA

{"golden_diff": "diff --git a/conda/common/signals.py b/conda/common/signals.py\n--- a/conda/common/signals.py\n+++ b/conda/common/signals.py\n@@ -4,6 +4,7 @@\n from contextlib import contextmanager\n from logging import getLogger\n import signal\n+import threading\n \n from .compat import iteritems\n \n@@ -17,7 +18,6 @@\n     'SIGBREAK',\n )\n \n-\n def get_signal_name(signum):\n     \"\"\"\n     Examples:\n@@ -33,18 +33,23 @@\n \n @contextmanager\n def signal_handler(handler):\n-    previous_handlers = []\n+    _thread_local = threading.local()\n+    _thread_local.previous_handlers = []\n     for signame in INTERRUPT_SIGNALS:\n         sig = getattr(signal, signame, None)\n         if sig:\n             log.debug(\"registering handler for %s\", signame)\n-            prev_handler = signal.signal(sig, handler)\n-            previous_handlers.append((sig, prev_handler))\n+            try:\n+                prev_handler = signal.signal(sig, handler)\n+                _thread_local.previous_handlers.append((sig, prev_handler))\n+            except ValueError as e:\n+                # ValueError: signal only works in main thread\n+                log.debug('%r', e)\n     try:\n         yield\n     finally:\n         standard_handlers = signal.SIG_IGN, signal.SIG_DFL\n-        for sig, previous_handler in previous_handlers:\n+        for sig, previous_handler in _thread_local.previous_handlers:\n             if callable(previous_handler) or previous_handler in standard_handlers:\n                 log.debug(\"de-registering handler for %s\", sig)\n                 signal.signal(sig, previous_handler)\ndiff --git a/conda/exports.py b/conda/exports.py\n--- a/conda/exports.py\n+++ b/conda/exports.py\n@@ -30,7 +30,7 @@\n from .gateways.connection import CondaSession  # NOQA\n CondaSession = CondaSession\n \n-from .common.toposort import _toposort\n+from .common.toposort import _toposort  # NOQA\n _toposort = _toposort\n \n from .gateways.disk.link import lchmod  # NOQA\n", "issue": "signal handler can only be used in main thread\nOften get these with conda-build tests\r\n\r\nhttps://travis-ci.org/conda/conda/jobs/225296134#L1380\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/travis/build/conda/conda/conda-build/conda_build/build.py\", line 688, in create_env\r\n    execute_actions(actions, index, verbose=config.debug)\r\n  File \"/home/travis/build/conda/conda/conda/plan.py\", line 612, in execute_actions\r\n    execute_instructions(plan, index, verbose)\r\n  File \"/home/travis/build/conda/conda/conda/instructions.py\", line 243, in execute_instructions\r\n    cmd(state, arg)\r\n  File \"/home/travis/build/conda/conda/conda/instructions.py\", line 98, in PROGRESSIVEFETCHEXTRACT_CMD\r\n    progressive_fetch_extract.execute()\r\n  File \"/home/travis/build/conda/conda/conda/core/package_cache.py\", line 491, in execute\r\n    with signal_handler(conda_signal_handler):\r\n  File \"/home/travis/miniconda/lib/python3.6/contextlib.py\", line 82, in __enter__\r\n    return next(self.gen)\r\n  File \"/home/travis/build/conda/conda/conda/common/signals.py\", line 41, in signal_handler\r\n    prev_handler = signal.signal(sig, handler)\r\n  File \"/home/travis/miniconda/lib/python3.6/signal.py\", line 47, in signal\r\n    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))\r\nValueError: signal only works in main thread\r\n```\nsignal handler can only be used in main thread\nOften get these with conda-build tests\r\n\r\nhttps://travis-ci.org/conda/conda/jobs/225296134#L1380\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/travis/build/conda/conda/conda-build/conda_build/build.py\", line 688, in create_env\r\n    execute_actions(actions, index, verbose=config.debug)\r\n  File \"/home/travis/build/conda/conda/conda/plan.py\", line 612, in execute_actions\r\n    execute_instructions(plan, index, verbose)\r\n  File \"/home/travis/build/conda/conda/conda/instructions.py\", line 243, in execute_instructions\r\n    cmd(state, arg)\r\n  File \"/home/travis/build/conda/conda/conda/instructions.py\", line 98, in PROGRESSIVEFETCHEXTRACT_CMD\r\n    progressive_fetch_extract.execute()\r\n  File \"/home/travis/build/conda/conda/conda/core/package_cache.py\", line 491, in execute\r\n    with signal_handler(conda_signal_handler):\r\n  File \"/home/travis/miniconda/lib/python3.6/contextlib.py\", line 82, in __enter__\r\n    return next(self.gen)\r\n  File \"/home/travis/build/conda/conda/conda/common/signals.py\", line 41, in signal_handler\r\n    prev_handler = signal.signal(sig, handler)\r\n  File \"/home/travis/miniconda/lib/python3.6/signal.py\", line 47, in signal\r\n    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))\r\nValueError: signal only works in main thread\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom functools import partial\nfrom logging import getLogger\nfrom warnings import warn\n\nlog = getLogger(__name__)\n\nfrom . import CondaError  # NOQA\nCondaError = CondaError\n\nfrom . import compat, plan  # NOQA\ncompat, plan = compat, plan\n\nfrom .api import get_index  # NOQA\nget_index = get_index\n\nfrom .cli.common import specs_from_args, spec_from_line, specs_from_url  # NOQA\nfrom .cli.conda_argparse import add_parser_prefix, add_parser_channels  # NOQA\nadd_parser_channels, add_parser_prefix = add_parser_channels, add_parser_prefix\nspecs_from_args, spec_from_line = specs_from_args, spec_from_line\nspecs_from_url = specs_from_url\n\nfrom .cli.conda_argparse import ArgumentParser  # NOQA\nArgumentParser = ArgumentParser\n\nfrom .common.compat import PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA\nPY3, StringIO,  input, iteritems, string_types, text_type = PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA\nfrom .gateways.connection import CondaSession  # NOQA\nCondaSession = CondaSession\n\nfrom .common.toposort import _toposort\n_toposort = _toposort\n\nfrom .gateways.disk.link import lchmod  # NOQA\nlchmod = lchmod\n\nfrom .fetch import TmpDownload  # NOQA\nTmpDownload = TmpDownload\nhandle_proxy_407 = lambda x, y: warn(\"handle_proxy_407 is deprecated. \"\n                                     \"Now handled by CondaSession.\")\nfrom .core.index import dist_str_in_index, fetch_index  # NOQA\ndist_str_in_index, fetch_index = dist_str_in_index, fetch_index\nfrom .core.package_cache import download, rm_fetched  # NOQA\ndownload, rm_fetched = download, rm_fetched\n\nfrom .install import package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA\npackage_cache, prefix_placeholder, rm_rf, symlink_conda = package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA\n\nfrom .gateways.disk.delete import delete_trash, move_to_trash  # NOQA\ndelete_trash, move_to_trash = delete_trash, move_to_trash\n\nfrom .core.linked_data import is_linked, linked, linked_data  # NOQA\nis_linked, linked, linked_data = is_linked, linked, linked_data\n\nfrom .misc import untracked, walk_prefix  # NOQA\nuntracked, walk_prefix = untracked, walk_prefix\n\nfrom .resolve import MatchSpec, NoPackagesFound, Resolve, Unsatisfiable, normalized_version  # NOQA\nMatchSpec, NoPackagesFound, Resolve = MatchSpec, NoPackagesFound, Resolve\nUnsatisfiable, normalized_version = Unsatisfiable, normalized_version\n\nfrom .signature import KEYS, KEYS_DIR, hash_file, verify  # NOQA\nKEYS, KEYS_DIR = KEYS, KEYS_DIR\nhash_file, verify = hash_file, verify\n\nfrom .utils import hashsum_file, human_bytes, memoized, unix_path_to_win, win_path_to_unix, url_path  # NOQA\nhashsum_file, human_bytes = hashsum_file, human_bytes\nmemoized, unix_path_to_win = memoized, unix_path_to_win\nwin_path_to_unix, url_path = win_path_to_unix, url_path\n\nfrom .gateways.disk.read import compute_md5sum  # NOQA\nmd5_file = compute_md5sum\n\nfrom .config import sys_rc_path  # NOQA\nsys_rc_path = sys_rc_path\n\nfrom .models.version import VersionOrder  # NOQA\nVersionOrder = VersionOrder\n\nimport conda.base.context  # NOQA\nfrom .base.context import get_prefix as context_get_prefix, non_x86_linux_machines  # NOQA\nnon_x86_linux_machines = non_x86_linux_machines\n\nfrom ._vendor.auxlib.entity import EntityEncoder        # NOQA\nEntityEncoder = EntityEncoder\nfrom .base.constants import DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA\nDEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX = DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA\nget_prefix = partial(context_get_prefix, conda.base.context.context)\nget_default_urls = lambda: DEFAULT_CHANNELS\n\narch_name = conda.base.context.context.arch_name\nbinstar_upload = conda.base.context.context.anaconda_upload\nbits = conda.base.context.context.bits\ndefault_prefix = conda.base.context.context.default_prefix\ndefault_python = conda.base.context.context.default_python\nenvs_dirs = conda.base.context.context.envs_dirs\npkgs_dirs = conda.base.context.context.pkgs_dirs\nplatform = conda.base.context.context.platform\nroot_dir = conda.base.context.context.root_prefix\nroot_writable = conda.base.context.context.root_writable\nsubdir = conda.base.context.context.subdir\nfrom .models.channel import get_conda_build_local_url  # NOQA\nget_rc_urls = lambda: list(conda.base.context.context.channels)\nget_local_urls = lambda: list(get_conda_build_local_url()) or []\nload_condarc = lambda fn: conda.base.context.reset_context([fn])\nfrom .exceptions import PaddingError  # NOQA\nPaddingError = PaddingError\nfrom .gateways.disk.link import CrossPlatformStLink  # NOQA\nCrossPlatformStLink = CrossPlatformStLink\n\nfrom .models.enums import FileMode  # NOQA\nFileMode = FileMode\nfrom .models.enums import PathType  # NOQA\nPathType = PathType\n\n\nif PY3:\n    import configparser  # NOQA  # pragma: py2 no cover\nelse:\n    import ConfigParser as configparser  # NOQA  # pragma: py3 no cover\nconfigparser = configparser\n\n\nfrom .compat import TemporaryDirectory  # NOQA\nTemporaryDirectory = TemporaryDirectory\n\nfrom .gateways.subprocess import ACTIVE_SUBPROCESSES, subprocess_call  # NOQA\nACTIVE_SUBPROCESSES, subprocess_call = ACTIVE_SUBPROCESSES, subprocess_call\n\nfrom .core.repodata import cache_fn_url  # NOQA\ncache_fn_url = cache_fn_url\n\n\nclass Completer(object):\n    def get_items(self):\n        return self._get_items()\n\n    def __contains__(self, item):\n        return True\n\n    def __iter__(self):\n        return iter(self.get_items())\n\nclass InstalledPackages(object): pass  # NOQA\n", "path": "conda/exports.py"}, {"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom contextlib import contextmanager\nfrom logging import getLogger\nimport signal\n\nfrom .compat import iteritems\n\nlog = getLogger(__name__)\n\nINTERRUPT_SIGNALS = (\n    'SIGABRT',\n    'SIGINT',\n    'SIGTERM',\n    'SIGQUIT',\n    'SIGBREAK',\n)\n\n\ndef get_signal_name(signum):\n    \"\"\"\n    Examples:\n        >>> from signal import SIGINT\n        >>> get_signal_name(SIGINT)\n        'SIGINT'\n\n    \"\"\"\n    return next((k for k, v in iteritems(signal.__dict__)\n                 if v == signum and k.startswith('SIG') and not k.startswith('SIG_')),\n                None)\n\n\n@contextmanager\ndef signal_handler(handler):\n    previous_handlers = []\n    for signame in INTERRUPT_SIGNALS:\n        sig = getattr(signal, signame, None)\n        if sig:\n            log.debug(\"registering handler for %s\", signame)\n            prev_handler = signal.signal(sig, handler)\n            previous_handlers.append((sig, prev_handler))\n    try:\n        yield\n    finally:\n        standard_handlers = signal.SIG_IGN, signal.SIG_DFL\n        for sig, previous_handler in previous_handlers:\n            if callable(previous_handler) or previous_handler in standard_handlers:\n                log.debug(\"de-registering handler for %s\", sig)\n                signal.signal(sig, previous_handler)\n", "path": "conda/common/signals.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom functools import partial\nfrom logging import getLogger\nfrom warnings import warn\n\nlog = getLogger(__name__)\n\nfrom . import CondaError  # NOQA\nCondaError = CondaError\n\nfrom . import compat, plan  # NOQA\ncompat, plan = compat, plan\n\nfrom .api import get_index  # NOQA\nget_index = get_index\n\nfrom .cli.common import specs_from_args, spec_from_line, specs_from_url  # NOQA\nfrom .cli.conda_argparse import add_parser_prefix, add_parser_channels  # NOQA\nadd_parser_channels, add_parser_prefix = add_parser_channels, add_parser_prefix\nspecs_from_args, spec_from_line = specs_from_args, spec_from_line\nspecs_from_url = specs_from_url\n\nfrom .cli.conda_argparse import ArgumentParser  # NOQA\nArgumentParser = ArgumentParser\n\nfrom .common.compat import PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA\nPY3, StringIO,  input, iteritems, string_types, text_type = PY3, StringIO,  input, iteritems, string_types, text_type  # NOQA\nfrom .gateways.connection import CondaSession  # NOQA\nCondaSession = CondaSession\n\nfrom .common.toposort import _toposort  # NOQA\n_toposort = _toposort\n\nfrom .gateways.disk.link import lchmod  # NOQA\nlchmod = lchmod\n\nfrom .fetch import TmpDownload  # NOQA\nTmpDownload = TmpDownload\nhandle_proxy_407 = lambda x, y: warn(\"handle_proxy_407 is deprecated. \"\n                                     \"Now handled by CondaSession.\")\nfrom .core.index import dist_str_in_index, fetch_index  # NOQA\ndist_str_in_index, fetch_index = dist_str_in_index, fetch_index\nfrom .core.package_cache import download, rm_fetched  # NOQA\ndownload, rm_fetched = download, rm_fetched\n\nfrom .install import package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA\npackage_cache, prefix_placeholder, rm_rf, symlink_conda = package_cache, prefix_placeholder, rm_rf, symlink_conda  # NOQA\n\nfrom .gateways.disk.delete import delete_trash, move_to_trash  # NOQA\ndelete_trash, move_to_trash = delete_trash, move_to_trash\n\nfrom .core.linked_data import is_linked, linked, linked_data  # NOQA\nis_linked, linked, linked_data = is_linked, linked, linked_data\n\nfrom .misc import untracked, walk_prefix  # NOQA\nuntracked, walk_prefix = untracked, walk_prefix\n\nfrom .resolve import MatchSpec, NoPackagesFound, Resolve, Unsatisfiable, normalized_version  # NOQA\nMatchSpec, NoPackagesFound, Resolve = MatchSpec, NoPackagesFound, Resolve\nUnsatisfiable, normalized_version = Unsatisfiable, normalized_version\n\nfrom .signature import KEYS, KEYS_DIR, hash_file, verify  # NOQA\nKEYS, KEYS_DIR = KEYS, KEYS_DIR\nhash_file, verify = hash_file, verify\n\nfrom .utils import hashsum_file, human_bytes, memoized, unix_path_to_win, win_path_to_unix, url_path  # NOQA\nhashsum_file, human_bytes = hashsum_file, human_bytes\nmemoized, unix_path_to_win = memoized, unix_path_to_win\nwin_path_to_unix, url_path = win_path_to_unix, url_path\n\nfrom .gateways.disk.read import compute_md5sum  # NOQA\nmd5_file = compute_md5sum\n\nfrom .config import sys_rc_path  # NOQA\nsys_rc_path = sys_rc_path\n\nfrom .models.version import VersionOrder  # NOQA\nVersionOrder = VersionOrder\n\nimport conda.base.context  # NOQA\nfrom .base.context import get_prefix as context_get_prefix, non_x86_linux_machines  # NOQA\nnon_x86_linux_machines = non_x86_linux_machines\n\nfrom ._vendor.auxlib.entity import EntityEncoder        # NOQA\nEntityEncoder = EntityEncoder\nfrom .base.constants import DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA\nDEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX = DEFAULT_CHANNELS, DEFAULT_CHANNELS_WIN, DEFAULT_CHANNELS_UNIX  # NOQA\nget_prefix = partial(context_get_prefix, conda.base.context.context)\nget_default_urls = lambda: DEFAULT_CHANNELS\n\narch_name = conda.base.context.context.arch_name\nbinstar_upload = conda.base.context.context.anaconda_upload\nbits = conda.base.context.context.bits\ndefault_prefix = conda.base.context.context.default_prefix\ndefault_python = conda.base.context.context.default_python\nenvs_dirs = conda.base.context.context.envs_dirs\npkgs_dirs = conda.base.context.context.pkgs_dirs\nplatform = conda.base.context.context.platform\nroot_dir = conda.base.context.context.root_prefix\nroot_writable = conda.base.context.context.root_writable\nsubdir = conda.base.context.context.subdir\nfrom .models.channel import get_conda_build_local_url  # NOQA\nget_rc_urls = lambda: list(conda.base.context.context.channels)\nget_local_urls = lambda: list(get_conda_build_local_url()) or []\nload_condarc = lambda fn: conda.base.context.reset_context([fn])\nfrom .exceptions import PaddingError  # NOQA\nPaddingError = PaddingError\nfrom .gateways.disk.link import CrossPlatformStLink  # NOQA\nCrossPlatformStLink = CrossPlatformStLink\n\nfrom .models.enums import FileMode  # NOQA\nFileMode = FileMode\nfrom .models.enums import PathType  # NOQA\nPathType = PathType\n\n\nif PY3:\n    import configparser  # NOQA  # pragma: py2 no cover\nelse:\n    import ConfigParser as configparser  # NOQA  # pragma: py3 no cover\nconfigparser = configparser\n\n\nfrom .compat import TemporaryDirectory  # NOQA\nTemporaryDirectory = TemporaryDirectory\n\nfrom .gateways.subprocess import ACTIVE_SUBPROCESSES, subprocess_call  # NOQA\nACTIVE_SUBPROCESSES, subprocess_call = ACTIVE_SUBPROCESSES, subprocess_call\n\nfrom .core.repodata import cache_fn_url  # NOQA\ncache_fn_url = cache_fn_url\n\n\nclass Completer(object):\n    def get_items(self):\n        return self._get_items()\n\n    def __contains__(self, item):\n        return True\n\n    def __iter__(self):\n        return iter(self.get_items())\n\nclass InstalledPackages(object): pass  # NOQA\n", "path": "conda/exports.py"}, {"content": "# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nfrom contextlib import contextmanager\nfrom logging import getLogger\nimport signal\nimport threading\n\nfrom .compat import iteritems\n\nlog = getLogger(__name__)\n\nINTERRUPT_SIGNALS = (\n    'SIGABRT',\n    'SIGINT',\n    'SIGTERM',\n    'SIGQUIT',\n    'SIGBREAK',\n)\n\ndef get_signal_name(signum):\n    \"\"\"\n    Examples:\n        >>> from signal import SIGINT\n        >>> get_signal_name(SIGINT)\n        'SIGINT'\n\n    \"\"\"\n    return next((k for k, v in iteritems(signal.__dict__)\n                 if v == signum and k.startswith('SIG') and not k.startswith('SIG_')),\n                None)\n\n\n@contextmanager\ndef signal_handler(handler):\n    _thread_local = threading.local()\n    _thread_local.previous_handlers = []\n    for signame in INTERRUPT_SIGNALS:\n        sig = getattr(signal, signame, None)\n        if sig:\n            log.debug(\"registering handler for %s\", signame)\n            try:\n                prev_handler = signal.signal(sig, handler)\n                _thread_local.previous_handlers.append((sig, prev_handler))\n            except ValueError as e:\n                # ValueError: signal only works in main thread\n                log.debug('%r', e)\n    try:\n        yield\n    finally:\n        standard_handlers = signal.SIG_IGN, signal.SIG_DFL\n        for sig, previous_handler in _thread_local.previous_handlers:\n            if callable(previous_handler) or previous_handler in standard_handlers:\n                log.debug(\"de-registering handler for %s\", sig)\n                signal.signal(sig, previous_handler)\n", "path": "conda/common/signals.py"}]}