Repository: conda/conda

Issue:
conda.common.signals.signal_handler throwing exceptions on travis
The conda.common.signals.signal_handler context manager [introduced in 4.3.14](https://github.com/conda/conda/compare/4.3.13...4.3.14#diff-1ce3aba0f5b5277dc9830e6671cab0f1R35) is causing my travis conda build to fail in the midst of a `conda build` command, throwing `TypeError`s - see [this travis build](https://travis-ci.org/ipython-contrib/jupyter_contrib_nbextensions/jobs/220349775#L633-L662) for a failed example, and then [this build using 4.3.13](https://travis-ci.org/ipython-contrib/jupyter_contrib_nbextensions/jobs/220359572) which does exactly the same with the earlier version which still works.

These builds still work fine for me locally (Ubuntu 16.04), so I assume this is something related to Travis (currenlty apparently using Ubuntu 12.04 or 14.04) somehow, although I'm not sure what...


Discussion:
Stacktrace from CI is

```
Traceback (most recent call last):
  File "/home/travis/miniconda/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 334, in main
    execute(sys.argv[1:])
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/cli/main_build.py", line 325, in execute
    noverify=args.no_verify)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/api.py", line 97, in build
    need_source_download=need_source_download, config=config)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/build.py", line 1503, in build_tree
    config=config)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/build.py", line 1019, in build
    create_env(config.build_prefix, specs, config=config)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda_build/build.py", line 688, in create_env
    execute_actions(actions, index, verbose=config.debug)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda/plan.py", line 809, in execute_actions
    execute_instructions(plan, index, verbose)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda/instructions.py", line 247, in execute_instructions
    cmd(state, arg)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda/instructions.py", line 100, in PROGRESSIVEFETCHEXTRACT_CMD
    progressive_fetch_extract.execute()
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda/core/package_cache.py", line 491, in execute
    self._execute_action(action)
  File "/home/travis/miniconda/lib/python3.6/contextlib.py", line 89, in __exit__
    next(self.gen)
  File "/home/travis/miniconda/lib/python3.6/site-packages/conda/common/signals.py", line 48, in signal_handler
    signal.signal(sig, previous_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))
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
```

Resolving patch:
diff --git a/conda/common/signals.py b/conda/common/signals.py
--- a/conda/common/signals.py
+++ b/conda/common/signals.py
@@ -43,6 +43,8 @@ def signal_handler(handler):
     try:
         yield
     finally:
+        standard_handlers = signal.SIG_IGN, signal.SIG_DFL
         for sig, previous_handler in previous_handlers:
-            log.debug("de-registering handler for %s", signame)
-            signal.signal(sig, previous_handler)
+            if callable(previous_handler) or previous_handler in standard_handlers:
+                log.debug("de-registering handler for %s", signame)
+                signal.signal(sig, previous_handler)


Test patch: