Reputation: 4330
I'm developing a web application using python and memcached.
First I want to start memcached from my python program, and if I'm right subprocess.Popen(["memcached"]);
will do it. What really bothers me is how to check if memcached is already running in the background.
I want something like
if check_memcached():
start_memcached();
The check_memcached()
function should return true if memcached is not already running. Anybody got any idea how to do this?
Upvotes: 4
Views: 5676
Reputation: 15776
The best way to check may depend on your platform. Here's some methods you could try:
/var/run/memcached.pid
and contains the process id of the running memcached daemon. To be extra sure you could read the PID contained in the file and verify that a process with this PID is still running.subprocess
module to run a command which can directly check for a locally running daemon. eg. Run the command pidof memcached
using subprocess
and check the return code.Upvotes: 5