greenlet don't like to access external elements (fixes #100)

parent c5153df6
......@@ -29,7 +29,7 @@ EXEMPT_METHODS = set(['OPTIONS'])
# Implement a "parallel loop" routine either with gipc or multiprocessing
# depending if we are under gunicorn or not
if IS_GUNICORN:
def parallel_loop(func=None, elem=None):
def parallel_loop(func=None, elem=None, *args, **kwargs):
import gevent
from gevent.queue import Queue
ret = []
......@@ -46,7 +46,9 @@ if IS_GUNICORN:
gevent.spawn(
func,
e,
output
output,
*args,
**kwargs
) for e in elem
]
# wait for process termination
......@@ -62,7 +64,7 @@ if IS_GUNICORN:
return ret
else:
def parallel_loop(func=None, elem=None):
def parallel_loop(func=None, elem=None, *args, **kwargs):
import multiprocessing
ret = []
......@@ -76,7 +78,8 @@ else:
processes = [
multiprocessing.Process(
target=func,
args=(e, output)
args=((e, output) + args),
kwargs=kwargs
) for e in elem
]
# start the processes
......
......@@ -56,24 +56,21 @@ class ServersStats(Resource):
r = []
if hasattr(api.bui.cli, 'servers'): # pragma: no cover
check = False
allowed = []
if (api.bui.acl and not
api.bui.acl.is_admin(current_user.get_id())):
check = True
allowed = api.bui.acl.servers(current_user.get_id())
def get_servers_info(serv, output):
def get_servers_info(serv, output, allowed, username):
try:
if check:
if serv in allowed:
output.put({
'name': serv,
'clients': len(api.bui.acl.clients(current_user.get_id(), serv)),
'alive': api.bui.cli.servers[serv].ping()
})
return
else:
if allowed and serv in allowed:
output.put({
'name': serv,
'clients': len(api.bui.acl.clients(username, serv)),
'alive': api.bui.cli.servers[serv].ping()
})
return
elif not allowed:
output.put({
'name': serv,
'clients': len(api.bui.cli.servers[serv].get_all_clients(serv)),
......@@ -84,6 +81,6 @@ class ServersStats(Resource):
except BUIserverException as e:
output.put(str(e))
r = parallel_loop(get_servers_info, api.bui.cli.servers)
r = parallel_loop(get_servers_info, api.bui.cli.servers, allowed, current_user.get_id())
return r
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment