Pickling problem - Bokeh server

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.

I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

1 Like

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

"""
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.
"""

The only potential solution I can imagine is to move *all* code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for __class__. However, you will simply have to try and see, I can't say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

···

On Feb 21, 2019, at 00:05, [email protected] wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named 'bk_script_1001'.

I think it is because the __class__ method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

1 Like

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

···

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, [email protected] wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

You should use a “Directory Style” organization for the app then you can import normally from the directory with the main.py

Thanks,

Bryan

···

On Feb 21, 2019, at 03:05, [email protected] wrote:

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, [email protected] wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/efdd990e-169b-4f56-822b-fc195a582b4e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

it works.

thank you very much.

···

On Sun, Feb 24, 2019, 20:43 Bryan Van de ven [email protected] wrote:

Hi,

You should use a “Directory Style” organization for the app then you can import normally from the directory with the main.py

Thanks,

Bryan

On Feb 21, 2019, at 03:05, [email protected] wrote:

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, [email protected] wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/efdd990e-169b-4f56-822b-fc195a582b4e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/Y5o602X1w2U/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/C0E6A5F9-B774-45B6-B548-6B301A90709D%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.