2 In order to detect a filehandle that's been closed, our only clue may be
3 the operating system returning the same filehandle in response to some
6 The builtins 'file' and 'open' are patched to collaborate with the
7 notify_opened protocol.
10 builtins_orig = __builtins__
12 from eventlet import hubs
13 from eventlet.hubs import hub
14 from eventlet.patcher import slurp_properties
17 __all__ = dir(builtins_orig)
18 __patched__ = ['file', 'open']
20 slurp_properties(builtins_orig, globals(),
21 ignore=__patched__, srckeys=dir(builtins_orig))
25 __original_file = file
28 class file(__original_file):
29 def __init__(self, *args, **kwargs):
30 super(file, self).__init__(*args, **kwargs)
31 hubs.notify_opened(self.fileno())
33 __original_open = open
39 result = __original_open(*args)
41 # This is incredibly ugly. 'open' is used under the hood by
42 # the import process. So, ensure we don't wind up in an
45 hubs.notify_opened(result.fileno())