Deploy Bokeh Server into production on IP address

Me neither. I would be happy to run multiple instances of the app on different ports. I just personally have zero experience with this stuff (I studied AI so hadn’t even heard of a port until using Bokeh)

I would ignore the 5/10 minutes to load, as that is just a function of how much data needs to be opened. I’m not sure what a server lifecycle hook does or how I would use it but if it would reduce the load time to instantly then I guess that would potentially solve the issue with the flask app.

Sorry again for my lack of knowledge regarding these things. I really do enjoy using Bokeh, the only reason I’m so stressed about this right now is because I thought multiprocess deployment would be easy and I already presented this to my bosses and said I would get a link to the group soon but I can’t of course because of these issues.

Not sure why this is happening if you’re indeed using unique addresses/port combinations in the multiple instances being run. Perhaps another process is already using the ports you’ve chosen.

Look here for information on the error for Windows systems, and one of the responses shows how to check for processes using the ports that are causing the errors.

https://stackoverflow.com/questions/12362542/python-server-only-one-usage-of-each-socket-address-is-normally-permitted

See the Directory Format section of the bokeh server user’s guide.

If you include an app_hooks.py file with the functions named therein, bokeh will run those at the appropriate times of the server lifecycle.

on_server_loaded() gets run when you start the server on your Windows machine.

on_session_created() gets run when each client session starts.

So if you need to do any setup work that is common to all users you could do that upfront when the server is spooled up via on_server_loaded() and have it ready to go when users connect.

I believe it’s overlapping because it won’t run unless the port referenced in server_document is 5006 so it has to be that one for both right now

Would I be able to save everything to a dictionary that is then referenced when different users log on? I already precompute everything in a single dictionary as is. And no user is ever changing data within my app. Are there any examples of this?

Oh no. That definitely won’t work and it doesn’t need to be that way.

See the example I posted for the waittress embed problem. Not for the server implementation, but just for how the ports and addresses were handled. I used variables defined at the topmost scope of the file and then referenced them everywhere the IP addresses and ports are prescribed.

My python code doesn’t seem to run when I do what you did though. Not sure what the issue is here.

Where does the server_context input to this function come from? Or is that not something I need to add? With respect to the on_server_loaded as in the documentation. And if I run some stuff in the app_hooks.py file, how do I then reference that dictionary in my main py file? I’m also a little confused with respect to running this as a flask app as I do now. It seems that lifecycle hooks need to be used with bokeh-serve which i don’t use.

You don’t need to provide it. Bokeh provides it for the server when it calls that method; you don’t explicitly call that method, bokeh will do it automatically if the app_hooks.py file exists in the directory structure.

What I think you need to do is assign our data to that server context. And then when the session is created for a given user, make a copy of it. I believe the server_context is accessible via the session context when the session created in on_session_created().

You have access to the session context as session_context property of the bokeh document for each client session.

How do i refer to session_context in my main.py file? Sorry for all of the questions, just struggling to find any examples.

My understanding is that your main.py is similar to the bokeh flask embed examples, wherein doc is an argument to the bk_app() function.

The session context is a property of a bokeh document, so look at doc.session_context If you can append/add data to it from the application lifecycle hooks in app_hooks.py, you should be able to access the info you need in that bk_app() function.

So can this be run in a Flask app and not Bokeh serve? I really don’t entirely understand how this is supposed to be done. The examples on github aren’t very clear. I have to get this done tonight because of all of the deployment issues, sorry for constantly bugging you.

Not a requirement for using a Flask app. I was just trying to tie it to what you originally posted.

It is really a function of how you’ve organized your code. If you hold on to the bokeh document for a session in a variable that is accessible to other parts of your code, you can access it as a property of the bokeh document. It has nothing to do with Flask per se. That is just how that original main.py file exposed the bokeh document.

I meant other way around. Seems from the documentation like running “bokeh serve” is a requirement for using lifecycle hooks. When I try to use them in a flask app, they don’t register. I’m unsure how I could use bokeh serve and still have other users on my network be able to use it.

Do you know if there’s any sort of bokeh support phone number I can call? Having a lot of trouble here and have been struggling for many hours with a very simple deployment issue that’s forcing me to change around my entire application @Bryan @_jm

No support number. The discourse forum is an entirely volunteer effort. And I’m just a user in no way affiliated with the bokeh project or development.

Ah okay didn’t realize that. @Bryan can I use lifecycle hooks in a Flask app? Are there any examples of this? This is really terrible that I can’t have multiple users use this app on Windows? I’m really upset.

I would really appreciate some support here.

You can use lifecycle hooks in a Flask context, but it is an advanced and uncommon thing to do, and does not have all the conveniences that the “directory format” bokeh server apps with an app_hooks.py file has. You will have to create an actual handler class to configure on the application:

from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
from bokeh.application.handlers.lifecycle import LifecycleHandler
class MyHandler(LifecycleHandler):
    def on_server_loaded(self, server_context):
        print("SERVER LOADED")
bkapp = Application(FunctionHandler(bkapp), MyHandler())

As for sharing data created in the server loaded hook, there’s a near infinite range of possibilities, from a shared database each session connects to, to pre-processed files that every session loads. Alternatively you can use Python a module that all sessions import. Have the hook store some module global and then all sessions that import the module will automatically see that immediately simply due to how Python itself caches modules. The spectrogram example does this with an audio.py module:

https://github.com/bokeh/bokeh/tree/branch-2.2/examples/app/spectrogram

This is really terrible that I can’t have multiple users use this app on Windows?

You can certainly have multiple users, in general. I just opened the bokeh serve --show sliders.py example on Windows and then opened 10 simultaneous windows. That’s just with one process, since the actual work the app does in callbacks is minimal. But if there is a long server startup time, or long individual session startup time, expensive blocking work in callbacks, all of these things will point towards more sophisticated approaches. Bokeh is not magic. If there is 10 minutes of startup time Bokeh can’t make that disappear. Whether and how things might become more involved and sophisticated to deal with situations like that depends on the actual specifics of what kind of work the app does, about which we know almost nothing.

Do you know if there’s any sort of bokeh support phone number I can call?
I would really appreciate some support here.

I just have to reiterate that Bokeh is an open source project run on a volunteer basis, not a business of any sort.

I’ve read through that example. I’m just creating a dictionary of dataframes that I need to call when running “bkapp,” That dictionary is reading from text files so if I have to read and write again, I’m not sure how well LifecycleHandlers will work relative to what I’m already doing.

To go back to the original issue, is there definitely no way to use multiple threads in Windows? I know that you can open 10 simple apps at the same time but if there’s a nonneglible load time then using one thread is really bulky.

I’m not meaning to criticize so I’m sorry if it came off that way, I just spent a month developing a bokeh app (during my first month of work ever, I just graduated from university) and thought it would be a relatively simple transition to allow it to work through multiple threads but I’m now being told that that doesn’t seem possible so naturally I’m a little distraught that I may have to go to my boss to tell him this needs to be redone in Javascript to function correctly (after I just presented the app to him and his bosses).

If you have any suggestions for how to use multiple threads in windows and avoid the Thread-1 error I was getting before, it would be incredibly appreciated. @Bryan