-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Multiple Bottle applications from the same source files #603
Comments
Try this:
instead of using |
Bottle appliction example: https://github.com/avelino/mining/blob/master/manage.py#L37:L40 |
@RonRothman The problem is related to the way python handle imports. The module is loaded only once in the namespace. |
@avelino thank you but that's completely unrelated to the issue, such example has a different module for each mounted application |
What is needed is a way to create bottle instances from a class. While this is easy to do it's unclear to me how to handle the routes. Decorators are clearly unusable as they work at the module level and cannot access to instance objects. Maybe adding the routes to each instance from inside the class could work. |
I guess I'm misunderstanding this: "multiple Bottle applications from the same source application." bottle.Bottle() acts differently from bottle.app(), in what I thought was precisely the way that you were concerned with:
Note that the latter method produces multiple distinct objects (apps), whereas the former does not. Hope that helps. |
@RonRothman your understanding of the issue is correct but unfortunately Bottle (or better Python in general) don't act as expected. Please consider the following sources:
app.py
Executing main.py produces the following output:
This means that load_app method has loaded the module only once (only one 'module imported' line was printed) and every object returned by the function in the app module refers always to the same object as you can see from both the same objects address and the last customer assignment repetead three times. |
Ah, thanks, that sample code is helpful. But I'm afraid that I see it acting precisely as expected. On the one hand, you say you want multiple (distinct) apps; but on the other hand, you're reusing the one app you've created (in If you want distinct apps, have
Here's the output this generates:
Does that do the trick? As an aside, you could also subclass
|
Hi sorry for the delay but I was a bit busy but I can now confirm you that the solution works pretty fine. Thank you @RonRothman Closing the bug now. |
Hello
Is it possible to create multiple Bottle applications from the same source module?
In my case I've an application that works with a database which depends on the source URL or the request.
In main.py:
In archive/app.py:
The documentation about load_app tells that a new application is created but in my case
all the three new_app objects results to be the same (because the source files are the same) and therefore all the use of app.customer results in the same customer3 value.
Is there a way to run multiple applications based on the same source files?
The text was updated successfully, but these errors were encountered: