Skip to content

Commit

Permalink
Merge pull request #525 from mawenzy/threading
Browse files Browse the repository at this point in the history
Increased thread id struct to work on 64bit Linux, fixes #524
  • Loading branch information
comrumino committed Feb 17, 2023
2 parents 18a44e5 + 07240b3 commit 1cea5ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions rpyc/core/brine.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@
C16 = Struct("!dd") # Successive floats (complex numbers)
I1 = Struct("!B") # Python type int w/ size [1] (ctype unsigned char)
I4 = Struct("!L") # Python type int w/ size [4] (ctype unsigned long)
# I4I4 is successive ints w/ size 4 and was introduced to pack local thread id and remote thread id
# Since PyThread_get_thread_ident returns a type of unsigned long, !LL can store both thread IDs.
I4I4 = Struct("!LL")
# I8I8 is successive ints w/ size 8 and was introduced to pack local thread id and remote thread id. Since
# PyThread_get_thread_ident returns a type of unsigned long, a platform dependent size, we
# need 8 bytes of length to support LP64/64-bit platforms. See
# - https://unix.org/whitepapers/64bit.html
# - https://en.wikipedia.org/wiki/Integer_(computer_science)#Long_integer
# TODO: Switch to native_id when 3.7 is EOL b/c PyThread_get_thread_ident is inheritly hosed due to casting.
I8I8 = Struct("!QQ")

_dump_registry = {}
_load_registry = {}
Expand Down
4 changes: 2 additions & 2 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _send(self, msg, seq, args): # IO
data = brine.dump((msg, seq, args))
if self._bind_threads:
this_thread = self._get_thread()
data = brine.I4I4.pack(this_thread.id, this_thread._remote_thread_id) + data
data = brine.I8I8.pack(this_thread.id, this_thread._remote_thread_id) + data
if msg == consts.MSG_REQUEST:
this_thread._occupation_count += 1
else:
Expand Down Expand Up @@ -549,7 +549,7 @@ def _serve_bound(self, timeout, wait_for_lock):

return False

remote_thread_id, local_thread_id = brine.I4I4.unpack(message[:16])
remote_thread_id, local_thread_id = brine.I8I8.unpack(message[:16])
message = message[16:]

this = False
Expand Down

0 comments on commit 1cea5ba

Please sign in to comment.