Repository: bokeh/bokeh

Issue:
Autoreloader cannot find bokeh on reload
I type command to serve my project:
`bokeh serve --show proj.py --dev proj.py`
By now everything works - I see correct results in my browser.

Later after changing and saving file proj.py bokeh tries to reload page and it crashes with message:

> can't open file 'D:\Anaconda\envs\pyt27\Scripts\bokeh': [Errno 2] No such file or directory

I have such file (precisely it's bokeh.exe seeing details of the file).
Also I have D:\Anaconda\envs\pyt27\Scripts in PATH environmental variable.
My environment:

bokeh: 1.0.2
python: 2.7.15
windows 7




Discussion:
I wonder if this is actually a Tornado issue. All we do on the Bokeh side besides calling watch on the extra files that need watching, is ultimately to pass `autoreload=True` to `tornado.web.Application` 

@bdarnell do you have any insights here?
@johny1614 can you execute the app with `bokeh.exe` from the command line, instead of `bokeh` ? If so, does that work? That simply may be the solution on windows, in which case we could add documentation about it. 
I don't know anything about these `.exe` wrappers, but I doubt invoking the script as `bokeh.exe` will make a difference. I've personally done very little work on windows (or anaconda for that matter); the only thing I'm sure I've tried on windows involving autoreload is invoking `c:\pythonXY\python.exe -m tornado.autoreload -m tornado.test`. 

Autoreload is sensitive to the `sys.argv` and `sys.executable` variables. Paths containing spaces have been problematic on windows before although comments indicate we've worked around those problems. Python 3.4 introduced some features that make autoreload slightly more robust. 
Ah that's another idea for starting the bokeh server:
```
python -m bokeh serve
```
That might provide a workable `sys.argv` in all cases. 
@johny1614 can you try out the suggestions above and report back? None of the core team is a regular windows user, so two minutes of your time would save much more effort on our end. 
I tried your idea @bryevdv and indeed its a workaround to the issue
I'm sorry, just realised there is a response.
running python -m bokeh serve proj.py --dev proj.py
Gives another error on reload (at start it's still fine):

```
Traceback (most recent call last):
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\__main__.py", line 76, in <module>
    main()
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\__main__.py", line 62, in main
    from bokeh.command.bootstrap import main as _main
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\command\bootstrap.py", line 55, in <module>
    from .util import die
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\command\util.py", line 33, in <module>
    from bokeh.application import Application
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\application\__init__.py", line 31, in <module>
    from .application import Application
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\application\application.py", line 39, in <module>
    from ..document import Document
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\document\__init__.py", line 29, in <module>
    from .document import DEFAULT_TITLE ; DEFAULT_TITLE
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\document\document.py", line 43, in <module>
    import jinja2
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\jinja2\__init__.py", line 41, in <module>
    from jinja2.bccache import BytecodeCache, FileSystemBytecodeCache, \
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\jinja2\bccache.py", line 23, in <module>
    import tempfile
  File "D:\Anaconda\envs\pyt27_2\lib\tempfile.py", line 32, in <module>
    import io as _io
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\io\__init__.py", line 52, in <module>
    from .export import export_png
  File "D:\Anaconda\envs\pyt27_2\lib\site-packages\bokeh\io\export.py", line 32, in <module>
    from tempfile import mkstemp
ImportError: cannot import name mkstemp
```
I inserted into file export.py a simple print line with sys.argv. Somehow it is called correctly at first time while running a server, but only after reload it finds difficulties to import mkstemp (having same sys.argv).
@johny1614 do you have this issue with any of the published examples? e.g. `sliders.py` Trying to determine whether there is something specific to your case or not. If the built in examples work then the best thing would be a compute minimal example to reproduce. 

FYI you don't need to pass the filename a second time after `--dev`

yup. Same error with sliders.py
Is there any chance your python installation is corrupted somehow? can you try in a fresh env?

@xavArtley just to clarify, your earlier report of success was on Windows?
Using different environment (windows 8.1) - same situation.
@bryevdv sorry for my late response I han't seen you referenced me
yes I reported success on Windows 7 using `python -m bokeh serve --dev`
@xavArtley would you mind making the small PR to document that windows users will need to run  bokeh server in this way for `--dev` to function? I think that is all we are able to do. 

Resolving patch:
diff --git a/bokeh/command/subcommands/serve.py b/bokeh/command/subcommands/serve.py
--- a/bokeh/command/subcommands/serve.py
+++ b/bokeh/command/subcommands/serve.py
@@ -521,16 +521,18 @@ class Serve(Subcommand):
             default = None,
             type    = str,
             nargs   = '*',
-            help    =   "Enable live reloading during app development."
-                        "By default it watches all *.py *.html *.css *.yaml files"
-                        "in the app directory tree. Additional files can be passed"
-                        "as arguments."
-                        "NOTE: This setting only works with a single app."
-                        "It also restricts the number of processes to 1.",
+            help    = "Enable live reloading during app development. "
+                      "By default it watches all *.py *.html *.css *.yaml files "
+                      "in the app directory tree. Additional files can be passed "
+                      "as arguments. "
+                      "NOTE: This setting only works with a single app. "
+                      "It also restricts the number of processes to 1. "
+                      "NOTE FOR WINDOWS USERS : this option must be invoked using "
+                      "'python -m bokeh'. If not Tornado will fail to restart the "
+                      "server",
         )),
     )
 
-
     def invoke(self, args):
         '''
 
@@ -638,15 +640,16 @@ def add_optional_autoreload_files(file_list):
             find_autoreload_targets(args.files[0])
             add_optional_autoreload_files(args.dev)
 
-
         with report_server_init_errors(**server_kwargs):
             server = Server(applications, **server_kwargs)
 
             if args.show:
+
                 # we have to defer opening in browser until we start up the server
                 def show_callback():
                     for route in applications.keys():
                         server.show(route)
+
                 server.io_loop.add_callback(show_callback)
 
             address_string = 'localhost'
@@ -672,6 +675,7 @@ def show_callback():
 # Code
 #-----------------------------------------------------------------------------
 
+
 __doc__ = format_docstring(__doc__,
     DEFAULT_PORT=DEFAULT_SERVER_PORT,
     LOGLEVELS=nice_join(LOGLEVELS),


Test patch:
diff --git a/bokeh/command/subcommands/tests/test_serve.py b/bokeh/command/subcommands/tests/test_serve.py
--- a/bokeh/command/subcommands/tests/test_serve.py
+++ b/bokeh/command/subcommands/tests/test_serve.py
@@ -223,12 +223,15 @@ def test_args():
             default = None,
             type    = str,
             nargs   = '*',
-            help    =   "Enable live reloading during app development."
-                        "By default it watches all *.py *.html *.css *.yaml files"
-                        "in the app directory tree. Additional files can be passed"
-                        "as arguments."
-                        "NOTE: This setting only works with a single app."
-                        "It also restricts the number of processes to 1.",
+            help    = "Enable live reloading during app development. "
+                      "By default it watches all *.py *.html *.css *.yaml files "
+                      "in the app directory tree. Additional files can be passed "
+                      "as arguments. "
+                      "NOTE: This setting only works with a single app. "
+                      "It also restricts the number of processes to 1. "
+                      "NOTE FOR WINDOWS USERS : this option must be invoked using "
+                      "'python -m bokeh'. If not Tornado will fail to restart the "
+                      "server",
         )),
     )