]> git.madduck.net Git - etc/vim.git/blobdiff - src/black/concurrency.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Reorganize changelog (#2669)
[etc/vim.git] / src / black / concurrency.py
index 119a9a71fafc8828913e9d91ae65df3dfb2aab0d..24f67b62f0617f79ab21fa9b036645338a4feb8e 100644 (file)
@@ -6,6 +6,21 @@ from typing import Any, Iterable
 from black.output import err
 
 
+def maybe_install_uvloop() -> None:
+    """If our environment has uvloop installed we use it.
+
+    This is called only from command-line entry points to avoid
+    interfering with the parent process if Black is used as a library.
+
+    """
+    try:
+        import uvloop
+
+        uvloop.install()
+    except ImportError:
+        pass
+
+
 def cancel(tasks: Iterable["asyncio.Task[Any]"]) -> None:
     """asyncio signal handler that cancels all `tasks` and reports to stderr."""
     err("Aborted!")
@@ -27,9 +42,12 @@ def shutdown(loop: asyncio.AbstractEventLoop) -> None:
 
         for task in to_cancel:
             task.cancel()
-        loop.run_until_complete(
-            asyncio.gather(*to_cancel, loop=loop, return_exceptions=True)
-        )
+        if sys.version_info >= (3, 7):
+            loop.run_until_complete(asyncio.gather(*to_cancel, return_exceptions=True))
+        else:
+            loop.run_until_complete(
+                asyncio.gather(*to_cancel, loop=loop, return_exceptions=True)
+            )
     finally:
         # `concurrent.futures.Future` objects cannot be cancelled once they
         # are already running. There might be some when the `shutdown()` happened.