Skip to content

Commit

Permalink
further improve thread wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
rlehfeld committed Sep 3, 2024
1 parent 07e80ac commit 966fb19
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
41 changes: 38 additions & 3 deletions RPyCRobotRemote/RPyCRobotRemoteServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,45 @@
class WrapTheadSpecific:
"""generic wrapper for any kind of object which makes it thread specific"""

# defined in object base class. To complete the wrapper, we must
# define all of these additionally
# ['__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
# '__init_subclass__', '__le__', '__lt__', '__ne__' '__reduce__',
# '__reduce_ex__', ]

def __init__(self, default=None):
object.__setattr__(self, '_local', threading.local())
object.__setattr__(self, '_default', default)
object.__setattr__(self, '__doc__', default.__doc__)
super().__setattr__('_local', threading.local())
super().__setattr__('_default', default)

@property
def __doc__(self, /):
return self.get_thread_specific_instance().__doc__

@property
def __match_args__(self, /):
return self.get_thread_specific_instance().__match_args__

@property
def __class__(self, /):
return self.get_thread_specific_instance().__class__

def __subclasshook__(self, sub):
return issubclass(self.get_thread_specific_instance(), sub)

def __subclasscheck__(self, sub):
return issubclass(self.get_thread_specific_instance(), sub)

def __dir__(self):
return dir(self.get_thread_specific_instance())

def __hash__(self):
return hash(self.get_thread_specific_instance())

def __str__(self):
return str(self.get_thread_specific_instance())

def __repr__(self):
return repr(self.get_thread_specific_instance())

def __getattr__(self, item):
return getattr(self.get_thread_specific_instance(), item)
Expand Down
2 changes: 1 addition & 1 deletion test/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Provider(),
serve=False,
# port=0,
port_file=sys.__stdout__,
port_file=sys.stdout,
server=RPyCRobotRemote.SingleServer
)

Expand Down

0 comments on commit 966fb19

Please sign in to comment.