Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2 incompatibility issue with execfile and bokeh server #5590

Closed
pzwang opened this Issue Dec 20, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@pzwang
Copy link

pzwang commented Dec 20, 2016

I have a bokeh server dashboard written in Python 2. It includes the use of print as a statement. When run by itself via bokeh serve --show step3.py, it runs just fine.

I then write a second script step4.py which uses execfile() on the first script, and then adds some additional logic of its own. Now I encounter a very strange problem:

2016-12-20 07:52:02,473 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x10bb20f50>: invalid syntax (step3.py, line 41)
File "step4.py", line 3, in <module>:
execfile("step3.py") Traceback (most recent call last):
  File "/Users/pwang/anaconda/envs/bokehdemo/lib/python2.7/site-packages/bokeh/application/handlers/code_runner.py", line 83, in run
    exec(self._code, module.__dict__)
  File "/Users/pwang/src/bokeh.demo/webinar/demo1/step4.py", line 3, in <module>
    execfile("step3.py")
  File "step3.py", line 41
    print attribute, "changed from '%s' to '%s'" % (old, new)
                  ^
SyntaxError: invalid syntax

I can verify that this is a print statement-related SyntaxError because if I put parentheses around this line, everything works fine. An additional interesting point of information is that in step4.py itself, I can put a print statement before the execfile("step3.py") call, and it works just fine.

So somehow, the logic in code_runner isn't accounting for execfile() behavior...? Or perhaps the import of print_function at the top of bokeh.application.handlers.code_runner is screwing things up?

I'll attach the relevant files later (they're being worked on right now).

@bryevdv

This comment has been minimized.

Copy link
Member

bryevdv commented Dec 20, 2016

Or perhaps the import of print_function at the top of bokeh.application.handlers.code_runner is screwing things up?

There's an easy one-character way to test that hypothesis. :) If that one change solves it, we can probably just comment it there out with a comment why. If not (is print_function scoped to modules? Or is an import anywhere some kind of global flag to the interpreter?), then I'm not sure there is anything that can be done.

@bryevdv

This comment has been minimized.

Copy link
Member

bryevdv commented Dec 22, 2016

@pzwang this should be fixed in master now but certainly a confirmation with your scripts would be valuable as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.