We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
WindowsError on dscheduler
So it appears that Bokeh is not found, but I have Bokeh and everything is up to date.

Interesting...

here lieth the traceback:

```
distributed.scheduler - INFO - Start Scheduler at:          192.168.0.7:8786
distributed.scheduler - INFO -            http at:          192.168.0.7:9786
distributed.scheduler - WARNING - Could not start Bokeh web UI
Traceback (most recent call last):
  File "C:\Anaconda\lib\site-packages\distributed\cli\dscheduler.py", line 88, in main
    bokeh_proc = subprocess.Popen(args)
  File "C:\Anaconda\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Anaconda\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Anaconda\Scripts\dscheduler-script.py", line 5, in <module>
    sys.exit(distributed.cli.dscheduler.go())
  File "C:\Anaconda\lib\site-packages\distributed\cli\dscheduler.py", line 107, in go
    main()
  File "C:\Anaconda\lib\site-packages\click\core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "C:\Anaconda\lib\site-packages\click\core.py", line 696, in main
    rv = self.invoke(ctx)
  File "C:\Anaconda\lib\site-packages\click\core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Anaconda\lib\site-packages\click\core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "C:\Anaconda\lib\site-packages\distributed\cli\dscheduler.py", line 100, in main
    bokeh_proc.terminate()
UnboundLocalError: local variable 'bokeh_proc' referenced before assignment
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `distributed/cli/dscheduler.py`
Content:
```
1 from __future__ import print_function, division, absolute_import
2 
3 import json
4 import logging
5 import multiprocessing
6 import os
7 import socket
8 import subprocess
9 import sys
10 from time import sleep
11 
12 import click
13 
14 import distributed
15 from distributed import Scheduler
16 from distributed.utils import get_ip
17 from distributed.http import HTTPScheduler
18 from distributed.cli.utils import check_python_3
19 from tornado.ioloop import IOLoop
20 
21 logger = logging.getLogger('distributed.scheduler')
22 
23 import signal
24 
25 def handle_signal(sig, frame):
26     IOLoop.instance().add_callback(IOLoop.instance().stop)
27 
28 signal.signal(signal.SIGINT, handle_signal)
29 signal.signal(signal.SIGTERM, handle_signal)
30 
31 
32 @click.command()
33 @click.argument('center', type=str, default='')
34 @click.option('--port', type=int, default=8786, help="Serving port")
35 @click.option('--http-port', type=int, default=9786, help="HTTP port")
36 @click.option('--bokeh-port', type=int, default=8787, help="HTTP port")
37 @click.option('--bokeh/--no-bokeh', '_bokeh', default=True, show_default=True,
38               required=False, help="Launch Bokeh Web UI")
39 @click.option('--host', type=str, default=None,
40               help="IP or hostname of this server")
41 @click.option('--show/--no-show', default=False, help="Show web UI")
42 @click.option('--bokeh-whitelist', default=None, multiple=True,
43               help="IP addresses to whitelist for bokeh.")
44 def main(center, host, port, http_port, bokeh_port, show, _bokeh, bokeh_whitelist):
45     given_host = host
46     host = host or get_ip()
47     ip = socket.gethostbyname(host)
48     loop = IOLoop.current()
49     scheduler = Scheduler(center, ip=ip,
50                           services={('http', http_port): HTTPScheduler})
51     if center:
52         loop.run_sync(scheduler.sync_center)
53     scheduler.start(port)
54 
55     if _bokeh:
56         try:
57             import bokeh
58             import distributed.bokeh
59             hosts = ['%s:%d' % (h, bokeh_port) for h in
60                      ['localhost', '127.0.0.1', ip, socket.gethostname(),
61                       host] + list(bokeh_whitelist)]
62             dirname = os.path.dirname(distributed.__file__)
63             paths = [os.path.join(dirname, 'bokeh', name)
64                      for name in ['status', 'tasks']]
65             binname = sys.argv[0][:-len('dscheduler')] + 'bokeh'
66             args = ([binname, 'serve'] + paths +
67                     ['--log-level', 'warning',
68                      '--check-unused-sessions=50',
69                      '--unused-session-lifetime=1',
70                      '--port', str(bokeh_port)] +
71                      sum([['--host', host] for host in hosts], []))
72             if show:
73                 args.append('--show')
74 
75             bokeh_options = {'host': host if given_host else '127.0.0.1',
76                              'http-port': http_port,
77                              'tcp-port': port,
78                              'bokeh-port': bokeh_port}
79             with open('.dask-web-ui.json', 'w') as f:
80                 json.dump(bokeh_options, f, indent=2)
81 
82             if sys.version_info[0] >= 3:
83                 from bokeh.command.bootstrap import main
84                 ctx = multiprocessing.get_context('spawn')
85                 bokeh_proc = ctx.Process(target=main, args=(args,))
86                 bokeh_proc.daemon = True
87                 bokeh_proc.start()
88             else:
89                 bokeh_proc = subprocess.Popen(args)
90 
91             logger.info(" Bokeh UI at:  http://%s:%d/status/"
92                         % (ip, bokeh_port))
93         except ImportError:
94             logger.info("Please install Bokeh to get Web UI")
95         except Exception as e:
96             logger.warn("Could not start Bokeh web UI", exc_info=True)
97 
98     loop.start()
99     loop.close()
100     scheduler.stop()
101     bokeh_proc.terminate()
102 
103     logger.info("End scheduler at %s:%d", ip, port)
104 
105 
106 def go():
107     check_python_3()
108     main()
109 
110 
111 if __name__ == '__main__':
112     go()
113
```
--- 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/distributed/cli/dscheduler.py b/distributed/cli/dscheduler.py
--- a/distributed/cli/dscheduler.py
+++ b/distributed/cli/dscheduler.py
@@ -62,7 +62,8 @@
             dirname = os.path.dirname(distributed.__file__)
             paths = [os.path.join(dirname, 'bokeh', name)
                      for name in ['status', 'tasks']]
-            binname = sys.argv[0][:-len('dscheduler')] + 'bokeh'
+            binname = 'bokeh.bat' if 'win' in sys.platform else 'bokeh'
+            binname = os.path.join(os.path.dirname(sys.argv[0]), binname)
             args = ([binname, 'serve'] + paths +
                     ['--log-level', 'warning',
                      '--check-unused-sessions=50',

{"golden_diff": "diff --git a/distributed/cli/dscheduler.py b/distributed/cli/dscheduler.py\n--- a/distributed/cli/dscheduler.py\n+++ b/distributed/cli/dscheduler.py\n@@ -62,7 +62,8 @@\n             dirname = os.path.dirname(distributed.__file__)\n             paths = [os.path.join(dirname, 'bokeh', name)\n                      for name in ['status', 'tasks']]\n-            binname = sys.argv[0][:-len('dscheduler')] + 'bokeh'\n+            binname = 'bokeh.bat' if 'win' in sys.platform else 'bokeh'\n+            binname = os.path.join(os.path.dirname(sys.argv[0]), binname)\n             args = ([binname, 'serve'] + paths +\n                     ['--log-level', 'warning',\n                      '--check-unused-sessions=50',\n", "issue": "WindowsError on dscheduler\nSo it appears that Bokeh is not found, but I have Bokeh and everything is up to date.\n\nInteresting...\n\nhere lieth the traceback:\n\n```\ndistributed.scheduler - INFO - Start Scheduler at:          192.168.0.7:8786\ndistributed.scheduler - INFO -            http at:          192.168.0.7:9786\ndistributed.scheduler - WARNING - Could not start Bokeh web UI\nTraceback (most recent call last):\n  File \"C:\\Anaconda\\lib\\site-packages\\distributed\\cli\\dscheduler.py\", line 88, in main\n    bokeh_proc = subprocess.Popen(args)\n  File \"C:\\Anaconda\\lib\\subprocess.py\", line 710, in __init__\n    errread, errwrite)\n  File \"C:\\Anaconda\\lib\\subprocess.py\", line 958, in _execute_child\n    startupinfo)\nWindowsError: [Error 2] The system cannot find the file specified\nTraceback (most recent call last):\n  File \"C:\\Anaconda\\Scripts\\dscheduler-script.py\", line 5, in <module>\n    sys.exit(distributed.cli.dscheduler.go())\n  File \"C:\\Anaconda\\lib\\site-packages\\distributed\\cli\\dscheduler.py\", line 107, in go\n    main()\n  File \"C:\\Anaconda\\lib\\site-packages\\click\\core.py\", line 716, in __call__\n    return self.main(*args, **kwargs)\n  File \"C:\\Anaconda\\lib\\site-packages\\click\\core.py\", line 696, in main\n    rv = self.invoke(ctx)\n  File \"C:\\Anaconda\\lib\\site-packages\\click\\core.py\", line 889, in invoke\n    return ctx.invoke(self.callback, **ctx.params)\n  File \"C:\\Anaconda\\lib\\site-packages\\click\\core.py\", line 534, in invoke\n    return callback(*args, **kwargs)\n  File \"C:\\Anaconda\\lib\\site-packages\\distributed\\cli\\dscheduler.py\", line 100, in main\n    bokeh_proc.terminate()\nUnboundLocalError: local variable 'bokeh_proc' referenced before assignment\n```\n\n", "before_files": [{"content": "from __future__ import print_function, division, absolute_import\n\nimport json\nimport logging\nimport multiprocessing\nimport os\nimport socket\nimport subprocess\nimport sys\nfrom time import sleep\n\nimport click\n\nimport distributed\nfrom distributed import Scheduler\nfrom distributed.utils import get_ip\nfrom distributed.http import HTTPScheduler\nfrom distributed.cli.utils import check_python_3\nfrom tornado.ioloop import IOLoop\n\nlogger = logging.getLogger('distributed.scheduler')\n\nimport signal\n\ndef handle_signal(sig, frame):\n    IOLoop.instance().add_callback(IOLoop.instance().stop)\n\nsignal.signal(signal.SIGINT, handle_signal)\nsignal.signal(signal.SIGTERM, handle_signal)\n\n\n@click.command()\n@click.argument('center', type=str, default='')\n@click.option('--port', type=int, default=8786, help=\"Serving port\")\n@click.option('--http-port', type=int, default=9786, help=\"HTTP port\")\n@click.option('--bokeh-port', type=int, default=8787, help=\"HTTP port\")\n@click.option('--bokeh/--no-bokeh', '_bokeh', default=True, show_default=True,\n              required=False, help=\"Launch Bokeh Web UI\")\n@click.option('--host', type=str, default=None,\n              help=\"IP or hostname of this server\")\n@click.option('--show/--no-show', default=False, help=\"Show web UI\")\n@click.option('--bokeh-whitelist', default=None, multiple=True,\n              help=\"IP addresses to whitelist for bokeh.\")\ndef main(center, host, port, http_port, bokeh_port, show, _bokeh, bokeh_whitelist):\n    given_host = host\n    host = host or get_ip()\n    ip = socket.gethostbyname(host)\n    loop = IOLoop.current()\n    scheduler = Scheduler(center, ip=ip,\n                          services={('http', http_port): HTTPScheduler})\n    if center:\n        loop.run_sync(scheduler.sync_center)\n    scheduler.start(port)\n\n    if _bokeh:\n        try:\n            import bokeh\n            import distributed.bokeh\n            hosts = ['%s:%d' % (h, bokeh_port) for h in\n                     ['localhost', '127.0.0.1', ip, socket.gethostname(),\n                      host] + list(bokeh_whitelist)]\n            dirname = os.path.dirname(distributed.__file__)\n            paths = [os.path.join(dirname, 'bokeh', name)\n                     for name in ['status', 'tasks']]\n            binname = sys.argv[0][:-len('dscheduler')] + 'bokeh'\n            args = ([binname, 'serve'] + paths +\n                    ['--log-level', 'warning',\n                     '--check-unused-sessions=50',\n                     '--unused-session-lifetime=1',\n                     '--port', str(bokeh_port)] +\n                     sum([['--host', host] for host in hosts], []))\n            if show:\n                args.append('--show')\n\n            bokeh_options = {'host': host if given_host else '127.0.0.1',\n                             'http-port': http_port,\n                             'tcp-port': port,\n                             'bokeh-port': bokeh_port}\n            with open('.dask-web-ui.json', 'w') as f:\n                json.dump(bokeh_options, f, indent=2)\n\n            if sys.version_info[0] >= 3:\n                from bokeh.command.bootstrap import main\n                ctx = multiprocessing.get_context('spawn')\n                bokeh_proc = ctx.Process(target=main, args=(args,))\n                bokeh_proc.daemon = True\n                bokeh_proc.start()\n            else:\n                bokeh_proc = subprocess.Popen(args)\n\n            logger.info(\" Bokeh UI at:  http://%s:%d/status/\"\n                        % (ip, bokeh_port))\n        except ImportError:\n            logger.info(\"Please install Bokeh to get Web UI\")\n        except Exception as e:\n            logger.warn(\"Could not start Bokeh web UI\", exc_info=True)\n\n    loop.start()\n    loop.close()\n    scheduler.stop()\n    bokeh_proc.terminate()\n\n    logger.info(\"End scheduler at %s:%d\", ip, port)\n\n\ndef go():\n    check_python_3()\n    main()\n\n\nif __name__ == '__main__':\n    go()\n", "path": "distributed/cli/dscheduler.py"}], "after_files": [{"content": "from __future__ import print_function, division, absolute_import\n\nimport json\nimport logging\nimport multiprocessing\nimport os\nimport socket\nimport subprocess\nimport sys\nfrom time import sleep\n\nimport click\n\nimport distributed\nfrom distributed import Scheduler\nfrom distributed.utils import get_ip\nfrom distributed.http import HTTPScheduler\nfrom distributed.cli.utils import check_python_3\nfrom tornado.ioloop import IOLoop\n\nlogger = logging.getLogger('distributed.scheduler')\n\nimport signal\n\ndef handle_signal(sig, frame):\n    IOLoop.instance().add_callback(IOLoop.instance().stop)\n\nsignal.signal(signal.SIGINT, handle_signal)\nsignal.signal(signal.SIGTERM, handle_signal)\n\n\n@click.command()\n@click.argument('center', type=str, default='')\n@click.option('--port', type=int, default=8786, help=\"Serving port\")\n@click.option('--http-port', type=int, default=9786, help=\"HTTP port\")\n@click.option('--bokeh-port', type=int, default=8787, help=\"HTTP port\")\n@click.option('--bokeh/--no-bokeh', '_bokeh', default=True, show_default=True,\n              required=False, help=\"Launch Bokeh Web UI\")\n@click.option('--host', type=str, default=None,\n              help=\"IP or hostname of this server\")\n@click.option('--show/--no-show', default=False, help=\"Show web UI\")\n@click.option('--bokeh-whitelist', default=None, multiple=True,\n              help=\"IP addresses to whitelist for bokeh.\")\ndef main(center, host, port, http_port, bokeh_port, show, _bokeh, bokeh_whitelist):\n    given_host = host\n    host = host or get_ip()\n    ip = socket.gethostbyname(host)\n    loop = IOLoop.current()\n    scheduler = Scheduler(center, ip=ip,\n                          services={('http', http_port): HTTPScheduler})\n    if center:\n        loop.run_sync(scheduler.sync_center)\n    scheduler.start(port)\n\n    if _bokeh:\n        try:\n            import bokeh\n            import distributed.bokeh\n            hosts = ['%s:%d' % (h, bokeh_port) for h in\n                     ['localhost', '127.0.0.1', ip, socket.gethostname(),\n                      host] + list(bokeh_whitelist)]\n            dirname = os.path.dirname(distributed.__file__)\n            paths = [os.path.join(dirname, 'bokeh', name)\n                     for name in ['status', 'tasks']]\n            binname = 'bokeh.bat' if 'win' in sys.platform else 'bokeh'\n            binname = os.path.join(os.path.dirname(sys.argv[0]), binname)\n            args = ([binname, 'serve'] + paths +\n                    ['--log-level', 'warning',\n                     '--check-unused-sessions=50',\n                     '--unused-session-lifetime=1',\n                     '--port', str(bokeh_port)] +\n                     sum([['--host', host] for host in hosts], []))\n            if show:\n                args.append('--show')\n\n            bokeh_options = {'host': host if given_host else '127.0.0.1',\n                             'http-port': http_port,\n                             'tcp-port': port,\n                             'bokeh-port': bokeh_port}\n            with open('.dask-web-ui.json', 'w') as f:\n                json.dump(bokeh_options, f, indent=2)\n\n            if sys.version_info[0] >= 3:\n                from bokeh.command.bootstrap import main\n                ctx = multiprocessing.get_context('spawn')\n                bokeh_proc = ctx.Process(target=main, args=(args,))\n                bokeh_proc.daemon = True\n                bokeh_proc.start()\n            else:\n                bokeh_proc = subprocess.Popen(args)\n\n            logger.info(\" Bokeh UI at:  http://%s:%d/status/\"\n                        % (ip, bokeh_port))\n        except ImportError:\n            logger.info(\"Please install Bokeh to get Web UI\")\n        except Exception as e:\n            logger.warn(\"Could not start Bokeh web UI\", exc_info=True)\n\n    loop.start()\n    loop.close()\n    scheduler.stop()\n    bokeh_proc.terminate()\n\n    logger.info(\"End scheduler at %s:%d\", ip, port)\n\n\ndef go():\n    check_python_3()\n    main()\n\n\nif __name__ == '__main__':\n    go()\n", "path": "distributed/cli/dscheduler.py"}]}