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
26 class file(__original_file):
27 def __init__(self, *args, **kwargs):
28 super(file, self).__init__(*args, **kwargs)
29 hubs.notify_opened(self.fileno())
31 __original_open = open
35 result = __original_open(*args)
37 # This is incredibly ugly. 'open' is used under the hood by
38 # the import process. So, ensure we don't wind up in an
41 hubs.notify_opened(result.fileno())