From 2c482276ed39112c650ed886c66d2c7b7d5e3783 Mon Sep 17 00:00:00 2001
From: Jim Crist-Harif <jcristharif@gmail.com>
Date: Tue, 10 Nov 2020 16:29:57 -0600
Subject: [PATCH 1/4] Python 3.9 compatibility
Bug: https://github.com/dask/distributed/issues/4168

---
 distributed/utils.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/distributed/utils.py b/distributed/utils.py
index 77487f8cec..c1a0d2caa8 100644
--- a/distributed/utils.py
+++ b/distributed/utils.py
@@ -72,6 +72,10 @@
 
 
 def _initialize_mp_context():
+    if not WINDOWS:
+        # For some reason this is required in python >= 3.9
+        import multiprocessing.popen_spawn_posix
+
     if WINDOWS or PYPY:
         return multiprocessing
     else:

From ef5bd0f8729a2c8c6f63c38dcac29020af01a7c4 Mon Sep 17 00:00:00 2001
From: Matthew Rocklin <mrocklin@gmail.com>
Date: Mon, 25 Jan 2021 10:51:36 -0800
Subject: [PATCH 2/4] import multiprocessing

---
 distributed/utils.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/distributed/utils.py b/distributed/utils.py
index a6af0b8f45..949b39cf52 100644
--- a/distributed/utils.py
+++ b/distributed/utils.py
@@ -10,7 +10,7 @@
 import html
 import json
 import logging
-import multiprocessing
+import multiprocessing  # noqa: F401
 import os
 import re
 import shutil
@@ -71,6 +71,8 @@
 
 
 def _initialize_mp_context():
+    import multiprocessing  # noqa: F401
+
     if not WINDOWS:
         # For some reason this is required in python >= 3.9
         import multiprocessing.popen_spawn_posix

From 60eecf8cf82026e4e48f570e255693bd01c3019b Mon Sep 17 00:00:00 2001
From: Matthew Rocklin <mrocklin@gmail.com>
Date: Mon, 25 Jan 2021 13:39:18 -0800
Subject: [PATCH 3/4] Add Python 3.9 to CI

---
 .github/workflows/ci-windows.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/ci-windows.yaml b/.github/workflows/ci-windows.yaml
index 6d5923eb18..a807bf187b 100644
--- a/.github/workflows/ci-windows.yaml
+++ b/.github/workflows/ci-windows.yaml
@@ -8,7 +8,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ["3.6", "3.7", "3.8"]
+        python-version: ["3.6", "3.7", "3.8", "3.9"]
 
     steps:
       - name: Checkout source

From 236f8af2e6ff2dc409f83dd0270620443943624f Mon Sep 17 00:00:00 2001
From: James Bourbeau <jrbourbeau@gmail.com>
Date: Tue, 26 Jan 2021 10:58:15 -0600
Subject: [PATCH 4/4] Update tornado install

---
 .github/workflows/ci-windows.yaml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/ci-windows.yaml b/.github/workflows/ci-windows.yaml
index a807bf187b..3fff13179f 100644
--- a/.github/workflows/ci-windows.yaml
+++ b/.github/workflows/ci-windows.yaml
@@ -33,10 +33,10 @@ jobs:
       - name: Install tornado
         shell: bash -l {0}
         run: |
-          if [[ "${{ matrix.python-version }}" = "3.8" ]]; then
-            conda install -c conda-forge tornado=6
-          else
+          if [[ "${{ matrix.python-version }}" = "3.6" ]]; then
             conda install -c conda-forge tornado=5
+          else
+            conda install -c conda-forge tornado=6
           fi
 
       - name: Install distributed from source
