Skip to content

Instantly share code, notes, and snippets.

@tivvit
Created August 24, 2015 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tivvit/c3652fdb6208752188fc to your computer and use it in GitHub Desktop.
Save tivvit/c3652fdb6208752188fc to your computer and use it in GitHub Desktop.
Correct usage of python aerospike client in forked server
#!/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