,
time.sleep(...), etcd , ,
. , ,
API, , .
1 ( multiprocessing):
import sh
import requests
import time
from multiprocessing import Process
etcd = Process(target=sh.etcd)
try:
etcd.start()
time.sleep(3)
r = requests.get('http://localhost:4001/v2/keys/')
print r.text
finally:
etcd.terminate()
multiprocessing
. ,
etcd.
2 ( ):
import os
import signal
import time
import requests
pid = os.fork()
if pid == 0:
os.execvp('etcd', ['etcd'])
try:
time.sleep(3)
r = requests.get('http://localhost:4001/v2/keys/')
print r.text
finally:
os.kill(pid, signal.SIGTERM)
It uses a traditional model forkand execthat works just as well in Python as it does in C. In this model, the output etcd
will be displayed on your console, which may or may not be what you want. You can control this by redirecting stdoutand stderrin the child process.
source
share