Skip to content

Commit

Permalink
Use getframe instead of stack
Browse files Browse the repository at this point in the history
  • Loading branch information
RouganStriker committed Aug 26, 2024
1 parent 6c86d8b commit 7119fe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions depocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import inspect
import sys
import threading


Expand Down Expand Up @@ -196,7 +197,7 @@ class will have its own stack and will be scoped independent of any

_Scoped__is_open = False
_Scoped__is_used = False
_Scoped__open_site = None
_Scoped__open_site_frame = None

def open(self, call_site_level=1):
"""
Expand Down Expand Up @@ -238,9 +239,13 @@ def open(self, call_site_level=1):
self._Scoped__is_open = True
self._Scoped__is_used = True

stack = inspect.stack()
if len(stack) > call_site_level:
self._Scoped__open_site = stack[call_site_level]
try:
frame = sys._getframe(call_site_level - 1)
except ValueError:
# No frame found, skip
pass
else:
self._Scoped__open_site_frame = frame

return self

Expand Down Expand Up @@ -287,7 +292,7 @@ def is_open(self):

@property
def open_site(self):
return self._Scoped__open_site
return inspect.getframeinfo(self._Scoped__open_site_frame)

@property
def is_used(self):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "depocs"
version = "2.0.0"
version = "2.0.0.dev1"
homepage = "https://github.com/sdelements/depocs"
description = "Scoped thread-local mixin class"
authors = ["Security Compass <[email protected]>"]
Expand Down

0 comments on commit 7119fe0

Please sign in to comment.