api: optimization in trampoline(): get rid of unnecessary functions, pass bound methods directly

This commit is contained in:
Denis Bilenko
2009-06-15 13:11:21 +07:00
parent f461e21459
commit 28b23e51f1

View File

@@ -145,21 +145,11 @@ def trampoline(fd, read=None, write=None, timeout=None, timeout_exc=TimeoutError
if error is None:
current.throw(socket.error(32, 'Broken pipe'))
else:
current.throw(getattr(error, 'value', error)) # convert to socket.error
def _do_timeout():
current.throw(timeout_exc())
def cb(d):
current.switch()
# with TwistedHub, descriptor is actually an object (socket_rwdescriptor) which stores
# this callback. If this callback stores a reference to the socket instance (fd)
# then descriptor has a reference to that instance. This makes socket not collected
# after greenlet exit. Since nobody actually uses the results of this switch, I removed
# fd from here. If it will be needed than an indirect reference which is discarded right
# after the switch above should be used.
current.throw(getattr(error, 'value', error)) # XXX convert to socket.error
if timeout is not None:
t = hub.schedule_call(timeout, _do_timeout)
t = hub.schedule_call(timeout, current.throw, timeout_exc)
try:
descriptor = hub.add_descriptor(fileno, read and cb, write and cb, _do_close)
descriptor = hub.add_descriptor(fileno, read and current.switch, write and current.switch, _do_close)
try:
return hub.switch()
finally: