Comments (6)
Hi matt, it seems neither invoking start() on container or runner will start service unless I call wait(). Is this expected?
from nameko.
@laike9m start()
does start the service, but you must wait()
on the container or the runner to stop your process or thread from exiting.
The best way to run a service is nameko run
on the command line. Or, if you want to embed the service in another application, wrap the run
function in nameko.cli.run
-- https://github.com/onefinestay/nameko/blob/master/nameko/cli/run.py#L117 (which is what the command line tool uses under the hood)
from nameko.
Thank you. I'm using a runner because in this way I'm able to stop the service programmatically. Actually there's another issue: I have to call kill()
to stop it while stop()
doesn't work.
from nameko.
Sorry, I forgot about this thread.
stop()
waits for all running workers and managed threads to exit gracefully. You can't expose container.stop()
in an entrypoint and expect to the container to stop when you call it -- this would create a deadlock between the container trying to stop and the worker or managed thread running the stop()
method.
If you want to expose an entrypoint that is capable of stopping the container, you'd need to do it "out of band" (i.e. using a thread that wasn't created by the container)
Here is a toy example that does that:
from nameko.rpc import rpc
from nameko.extensions import DependencyProvider
import eventlet
class Stopper(DependencyProvider):
def stop(self):
# can't use container.spawn_managed_thread here either
eventlet.spawn_n(self.container.stop)
def get_dependency(self, worker_ctx):
return self
class Service(object):
name = "stop"
stopper = Stopper()
@rpc
def stop(self):
self.stopper.stop()
return "stopping"
(tmp-6d6e28416a4d3fa9)Matts-13-inch-Macbook-Pro:tmp mattbennett$ nameko run stop
starting services: stop
Connected to amqp://guest:**@127.0.0.1:5672//
(tmp-6d6e28416a4d3fa9)Matts-13-inch-Macbook-Pro:~ mattbennett$ nameko shell
Nameko Python 2.7.10 (default, Jul 6 2015, 15:19:48)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] shell on darwin
Broker: amqp://guest:guest@localhost
>>> n.rpc.stop.stop()
from nameko.
it seems unusual to expose an endpoint to remotely shut down a service. is this definitely what you want when you say "stop the service programatically". Typically this is done e.g. via a process manager like supervisor, which stops (or kills) the service via posix signals. E.g. nameko run
listens for SIGTERM
and calls stop
from nameko.
Yes indeed, the example above is not a demonstration of how you should achieve this. It is only meant to illustrate an "out of band" thread.
Generating a SIGTERM
signal is a much better way to have the container to stop gracefully.
from nameko.
Related Issues (20)
- Why using dnspython 1.x instead of 2.x ? HOT 8
- need upgrade to support python 3.10 HOT 2
- Publisher crashing when exchange is provided and RabbitMQ is down
- Nameko crashes when consuming illegal messages HOT 6
- [ DOUBT ] Events Pub / Sub - How can I make a consumer only run one event at a time
- from nameko.rpc import rpc class GreetingService: name = "greeting_service" def hello(self, name): return "Hello, {}!".format(name)
- Timer work on master process or every process? HOT 2
- dnspython dependency version overly restrictive HOT 3
- "verify_amqp_uri" in the module "nameko.amqp.utils" had been removed? HOT 2
- Should HttpRequestHandler print out the exception to the browser? HOT 2
- nameko multiprocess problem HOT 1
- Do you die? we need you to improve Nameko Library HOT 5
- DB Migrations not working with Flask-Migrate HOT 2
- Linking nameko and golang by RPC HOT 1
- dnspython version HOT 1
- nameko run faild when httpx installed
- event_handler should be agnostic to dispatching service
- Drop support for Python 3.5 through 3.7
- directly connect to a RabbitMQ cluster
- Error after eventlet update to 0.34.x
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nameko.