Discussion:
[bottlepy] Running several apps on different interfaces simultaneously
PK
2015-09-26 21:03:20 UTC
Permalink
Hello fellow bottlers!

Your advise is needed.

I'd like to run 2 different Bottle() apps on different interfaces (it is a
must).
These two Bottle() apps share same state (this is also a must).
How should I do that?

in the code below the second run() would never be called, because first
run() is blocking

import json
from bottle import Bottle, run, response


STATE = {'some':'sate-here'}

external = Bottle()
internal = Bottle()

@external.get('/')
def get():
return json.dumps(STATE)

@internal.post('/')
def update():
# update STATE here
pass


if __name__ == 'main':
run(app=external, host='192.168.1.1', port=8080)
run(app=internal, host='localhost', port=4040)
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'gNeandr' via bottlepy
2015-09-26 22:04:04 UTC
Permalink
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Iuri
2015-09-26 22:28:37 UTC
Permalink
Can you maintain your STATE out of your main processes?

If your state is saved for example in a database, you can share it between
different instances. This way, you can just serve both apps separatelly.

On Sat, Sep 26, 2015 at 7:04 PM, 'gNeandr' via bottlepy <
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Avelino
2015-09-26 23:48:57 UTC
Permalink
I recommend using a WSGI HTTP Server to up more than a process,
example gunicorn
Post by Iuri
Can you maintain your STATE out of your main processes?
If your state is saved for example in a database, you can share it between
different instances. This way, you can just serve both apps separatelly.
On Sat, Sep 26, 2015 at 7:04 PM, 'gNeandr' via bottlepy <
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
PK
2015-09-27 13:00:21 UTC
Permalink
My current solution is to use *paste* as a server (), launch external and
internal apps with the Thread-start-join.
if__name__=='__main__':
from threading import Thread
ext_thread =Thread(target=externalApi, kwargs={..., server:'paste'})
ext_thread.start()

# same for internal
# then:
ext_thread.join()
int_thread.join()


I hope it will not impact performance, alas this is service will never see
more than 1000 requests per month(!).
Post by Avelino
I recommend using a WSGI HTTP Server to up more than a process,
example gunicorn
Post by Iuri
Can you maintain your STATE out of your main processes?
If your state is saved for example in a database, you can share it
between different instances. This way, you can just serve both apps
separatelly.
On Sat, Sep 26, 2015 at 7:04 PM, 'gNeandr' via bottlepy <
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
PK
2015-09-27 13:06:06 UTC
Permalink
hmmm

that's corrected one:

if __name__ == 'main':
from threading import Thread
ext_thread = Thread(target=bottle.run, kwargs={'app':external, 'host':'192.168.1.1', 'port': 8080, 'server':'paste'})

# ...
# ...

# ...
# ...
Post by PK
My current solution is to use *paste* as a server (), launch external and
internal apps with the Thread-start-join.
from threading import Thread
ext_thread =Thread(target=externalApi, kwargs={..., server:'paste'})
ext_thread.start()
# same for internal
ext_thread.join()
int_thread.join()
I hope it will not impact performance, alas this is service will never see
more than 1000 requests per month(!).
Post by Avelino
I recommend using a WSGI HTTP Server to up more than a process,
example gunicorn
Post by Iuri
Can you maintain your STATE out of your main processes?
If your state is saved for example in a database, you can share it
between different instances. This way, you can just serve both apps
separatelly.
On Sat, Sep 26, 2015 at 7:04 PM, 'gNeandr' via bottlepy <
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
PK
2015-09-27 12:51:44 UTC
Permalink
Tank you. It's good solution indeed.

Also, the issue I'm solving is "*make a control interface for a stateless
script*". The solution should be as simple as possible.
The stateless script checks internal interface; humans change state on
external interface via browser.
The Bottle application is state-holder.

More serious app should extract state into external component, no doubt, as
you proposed,
Post by Iuri
Can you maintain your STATE out of your main processes?
If your state is saved for example in a database, you can share it between
different instances. This way, you can just serve both apps separatelly.
On Sat, Sep 26, 2015 at 7:04 PM, 'gNeandr' via bottlepy <
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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
For more options, visit https://groups.google.com/d/optout.
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
PK
2015-09-27 12:43:07 UTC
Permalink
That's how I do it now. I use Thread(target=external, kwargs={...}) then
usual start-join pair.
I find it a bit weird how it is written.
Post by 'gNeandr' via bottlepy
How about using Multiprocessing/Threads to start one or both jobs parallel?
--
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...