inconsistent response using bottle + Apache + mod_wsgi

40 views
Skip to first unread message

Mark Luszniak

unread,
Jan 7, 2018, 6:17:05 AM1/7/18
to bottlepy
Disclaimer: I'm fairly new to Bottle but have 5+ years of Python experience. I've browsed back through this group for a year or two, and not seen anything similar to my issue, so I apologise if this has been covered previously.

Does bottle cache imported python modules?

I'll take a simple stab at explaining the problem... 

if I point my browser at the defined url, it might give behaviour 1, 2 or 3 (see below). 
If I refresh, I'll get the same behaviour, so if I see behaviour 2, each refresh will give behaviour 2. 
if I hit the back, and then forward buttons, I'll likely see a different behaviour, so if I was seeing 2, I might see 1 or 3
If I refresh, I'll get the same behaviour, so if I see behaviour 1 or 3, each refresh will give the same behavior. 

behaviour 1: app returns expected output

behaviour 2: app returns output from some early code that no longer exists in my source .py files, or .pyc filles

behaviour 3: a server error relating the function linked to the route

This inconsistent behaviour has me wondering if libraries / .pyc files are being cached - especially since behaviour 2 does not result from the current code?

Oh, and I've done a system wide search looking for duplicates of my .py / .pyc files; they only appear to exist in the one expected location, but I suppose they could be being cached with a different name?

Am I missing something silly?


Mark Luszniak

unread,
Jan 11, 2018, 1:56:38 PM1/11/18
to bottlepy
I've seen the same behaviour with Flask.

It seems that making substantive changes to the .py modules requires a restart of Apache.

I guess this does imply that the modules are being cached?

peb aryan

unread,
Jan 12, 2018, 3:10:56 AM1/12/18
to bott...@googlegroups.com
probably this is your browser. can you tell how is your app deployed?

--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcel Hellkamp

unread,
Jan 12, 2018, 8:08:30 AM1/12/18
to bott...@googlegroups.com
On 01/07/2018 08:55 AM, Mark Luszniak wrote:
Does bottle cache imported python modules?

No, but Python does. You are probably using an application server (apache+mod_wsgi or nginx+uwsgi or something similar) that starts multiple processes with multiple python interpreters. Each one loads modules only once, probably at the time the first request arrives. This is why you see inconsistent behavior: You are hitting different worker-processes with different versions of your application with each request.

Either use the built-in development server with the auto-reloading feature enabled which can detect changes and reload the process automatically, or continue using apache/nginx/whatever and restart after you made changes to your application.

This is not specific to Bottle. You will see this behavior with any modern web stack other than PHP.

--
Marcel
Reply all
Reply to author
Forward
0 new messages