Created
August 24, 2015 08:37
-
-
Save tivvit/c3652fdb6208752188fc to your computer and use it in GitHub Desktop.
Correct usage of python aerospike client in forked server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
import random | |
import aerospike | |
import os, sys | |
cli = aerospike.client( | |
{ | |
"hosts": [("aeros4", 3000), ("aeros1", 3000), ("aeros2", 3000), ("aeros3", 3000)], | |
"policies": { | |
"timeout": 10000, | |
"retry": aerospike.POLICY_RETRY_ONCE, | |
}, | |
"shm": {} | |
} | |
) | |
if __name__ == '__main__': | |
a = cli.connect() | |
p = os.getpid() | |
for i in range(0,100): | |
child_pid = os.fork() | |
random.seed(child_pid) | |
if child_pid == 0: break | |
# daemonize process | |
# if p == os.getpid(): sys.exit(0) | |
while True: | |
r = random.randint(1, 10000) | |
try: | |
a.put(("test", "rand", r), {"val": r}) | |
except Exception as e: | |
print("Error: {0}".format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment