Issue 6581. Michael Foord
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 3305c8d..30ee670 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -952,7 +952,10 @@
         tb = tb.tb_next
     return framelist
 
-currentframe = sys._getframe
+if hasattr(sys, '_getframe'):
+    currentframe = sys._getframe
+else:
+    currentframe = lambda _=None: None
 
 def stack(context=1):
     """Return a list of records for the stack above the caller's frame."""