added a few asserts to check that api functions are not called from the mainloop greenlet

This commit is contained in:
Denis Bilenko
2008-11-19 14:33:18 +06:00
parent 7691003399
commit 704e69569b

View File

@@ -136,6 +136,7 @@ def trampoline(fd, read=None, write=None, timeout=None, timeout_exc=TimeoutError
t = None t = None
hub = get_hub() hub = get_hub()
self = greenlet.getcurrent() self = greenlet.getcurrent()
assert hub.greenlet is not self, 'do not call blocking functions from the mainloop'
fileno = getattr(fd, 'fileno', lambda: fd)() fileno = getattr(fd, 'fileno', lambda: fd)()
def _do_close(_d, error=None): def _do_close(_d, error=None):
greenlib.switch(self, exc=getattr(error, 'value', None)) # convert to socket.error greenlib.switch(self, exc=getattr(error, 'value', None)) # convert to socket.error
@@ -175,6 +176,7 @@ def select(read_list, write_list, error_list, timeout=None):
self = get_hub() self = get_hub()
t = None t = None
current = greenlet.getcurrent() current = greenlet.getcurrent()
assert self.greenlet is not current, 'do not call blocking functions from the mainloop'
ds = {} ds = {}
for r in read_list: for r in read_list:
ds[get_fileno(r)] = {'read' : r} ds[get_fileno(r)] = {'read' : r}
@@ -419,6 +421,7 @@ def sleep(seconds=0):
nothing else will run. nothing else will run.
""" """
hub = get_hub() hub = get_hub()
assert hub.greenlet is not greenlet.getcurrent(), 'do not call blocking functions from the mainloop'
timer = hub.schedule_call(seconds, greenlib.switch, greenlet.getcurrent()) timer = hub.schedule_call(seconds, greenlib.switch, greenlet.getcurrent())
try: try:
hub.switch() hub.switch()