Re: [PATCH] Stop using deprecated thread.setDaemon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again,

I've fixed a couple more deprecation warnings. See attached patch.

BR,
Alex

On 9/13/23 18:32, Calum Mackay wrote:
On 13/09/2023 11:46 am, Alexander Zeijlon wrote:
The thread.setDaemon method is deprecated since Python version 3.10, the
daemon property should now be set directly.

Thanks Alexander, I'll add this to my list.

cheers,
calum.


Signed-off-by: Alexander Zeijlon <alexander.zeijlon@xxxxxxxxx>
---
  nfs4.0/nfs4lib.py                   | 2 +-
  nfs4.0/servertests/st_delegation.py | 4 ++--
  nfs4.1/nfs4state.py                 | 2 +-
  rpc/rpc.py                          | 4 ++--
  4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/nfs4.0/nfs4lib.py b/nfs4.0/nfs4lib.py
index 9b074f0..9a72ec9 100644
--- a/nfs4.0/nfs4lib.py
+++ b/nfs4.0/nfs4lib.py
@@ -297,7 +297,7 @@ class NFS4Client(rpc.RPCClient):
          # Start up callback server associated with this client
          self.cb_server = CBServer(self)
          self.thread = threading.Thread(target=self.cb_server.run, name=name)
-        self.thread.setDaemon(True)
+        self.thread.daemon = True
          self.thread.start()
          # Establish callback control socket
          self.cb_control = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/nfs4.0/servertests/st_delegation.py b/nfs4.0/servertests/st_delegation.py
index ba49cf9..bcc768a 100644
--- a/nfs4.0/servertests/st_delegation.py
+++ b/nfs4.0/servertests/st_delegation.py
@@ -40,7 +40,7 @@ def _recall(c, thisop, cbid):
      if res is not None and res.status != NFS4_OK:
          t_error = _handle_error(c, res, ops)
          t = threading.Thread(target=t_error.run)
-        t.setDaemon(1)
+        t.daemon = True
          t.start()
      return res
  @@ -409,7 +409,7 @@ def testChangeDeleg(t, env, funct=_recall):
      new_server = CBServer(c)
      new_server.set_cb_recall(c.cbid, funct, NFS4_OK);
      cb_thread = threading.Thread(target=new_server.run)
-    cb_thread.setDaemon(1)
+    cb_thread.daemon = True
      cb_thread.start()
      c.cb_server = new_server
      env.sleep(3)
diff --git a/nfs4.1/nfs4state.py b/nfs4.1/nfs4state.py
index e57b90a..6b4cc81 100644
--- a/nfs4.1/nfs4state.py
+++ b/nfs4.1/nfs4state.py
@@ -308,7 +308,7 @@ class DelegState(FileStateTyped):
                  e.status = CB_INIT
                  t = threading.Thread(target=e.initiate_recall,
                                       args=(dispatcher,))
-                t.setDaemon(True)
+                t.daemon = True
                  t.start()
          # We need to release the lock so that delegations can be recalled,
          # which can involve operations like WRITE, LOCK, OPEN, etc,
diff --git a/rpc/rpc.py b/rpc/rpc.py
index 1fe285a..3621c8e 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -598,7 +598,7 @@ class ConnectionHandler(object):
              log_p.log(5, "Received record from %i" % fd)
              log_p.log(2, repr(r))
              t = threading.Thread(target=self._event_rpc_record, args=(r, s))
-            t.setDaemon(True)
+            t.daemon = True
              t.start()
        def _event_rpc_record(self, record, pipe):
@@ -935,7 +935,7 @@ class Client(ConnectionHandler):
            # Start polling
          t = threading.Thread(target=self.start, name="PollingThread")
-        t.setDaemon(True)
+        t.daemon = True
          t.start()
        def send_call(self, pipe, procedure, data=b'', credinfo=None,
From 9137536a6d95bf46eea5cf35b54902805195b930 Mon Sep 17 00:00:00 2001
From: Alexander Zeijlon <alexander.zeijlon@xxxxxxxxx>
Date: Fri, 15 Sep 2023 09:07:45 +0200
Subject: [PATCH 2/2] Stop using deprecated threading function-aliases

We want to use the referenced functions instead of their deprecated
aliases.

Signed-off-by: Alexander Zeijlon <alexander.zeijlon@xxxxxxxxx>
---
 nfs4.0/lib/rpc/rpc.py                     | 14 +++++++-------
 nfs4.0/lib/rpc/rpcsec/sec_auth_gss.py     |  6 +++---
 nfs4.1/locking.py                         |  8 ++++----
 nfs4.1/nfs4state.py                       |  4 ++--
 nfs4.1/server41tests/st_create_session.py |  4 ++--
 rpc/rpc.py                                |  2 +-
 6 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/nfs4.0/lib/rpc/rpc.py b/nfs4.0/lib/rpc/rpc.py
index 24a7fc7..bd4b20e 100644
--- a/nfs4.0/lib/rpc/rpc.py
+++ b/nfs4.0/lib/rpc/rpc.py
@@ -187,7 +187,7 @@ class RPCClient(object):
                  program=None, version=None, sec_list=None, timeout=15.0,
                  uselowport=False):
         self.debug = 0
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock = threading.Lock()
         res = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
         self.af, socktype, proto, cannonname, self.sa = res[0]
@@ -234,7 +234,7 @@ class RPCClient(object):
                     return
 
     def getsocket(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._socket:
             out = self._socket[t]
@@ -250,7 +250,7 @@ class RPCClient(object):
     socket = property(getsocket)
 
     def getrpcpacker(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._rpcpacker:
             out = self._rpcpacker[t]
@@ -261,7 +261,7 @@ class RPCClient(object):
         return out
 
     def getrpcunpacker(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._rpcunpacker:
             out = self._rpcunpacker[t]
@@ -284,7 +284,7 @@ class RPCClient(object):
             return "%s\n%s" % (self.header, self.data)
 
     def add_outstanding_xids(self, xid, header, data, cred, proc):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._xidlist:
             if xid in self._xidlist[t]: raise
@@ -294,14 +294,14 @@ class RPCClient(object):
         self.lock.release()
 
     def get_outstanding_xids(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         out = self._xidlist[t]
         self.lock.release()
         return out
 
     def reconnect(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         self._socket[t].close()
         out = self._socket[t] = socket.socket(self.af, socket.SOCK_STREAM)
diff --git a/nfs4.0/lib/rpc/rpcsec/sec_auth_gss.py b/nfs4.0/lib/rpc/rpcsec/sec_auth_gss.py
index 6577fcf..637bdbb 100644
--- a/nfs4.0/lib/rpc/rpcsec/sec_auth_gss.py
+++ b/nfs4.0/lib/rpc/rpcsec/sec_auth_gss.py
@@ -92,7 +92,7 @@ def hint_string(d):
 class SecAuthGss(SecFlavor):
     krb5_oid = "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"
     def __init__(self, service=rpc_gss_svc_none):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock = threading.Lock()
         self.gss_seq_num = 0
         self.init = 1
@@ -101,7 +101,7 @@ class SecAuthGss(SecFlavor):
         self._unpacker = {t : gss_pack.GSSUnpacker('')}
 
     def getpacker(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._packer:
             out = self._packer[t]
@@ -112,7 +112,7 @@ class SecAuthGss(SecFlavor):
         return out
 
     def getunpacker(self):
-        t = threading.currentThread()
+        t = threading.current_thread()
         self.lock.acquire()
         if t in self._unpacker:
             out = self._unpacker[t]
diff --git a/nfs4.1/locking.py b/nfs4.1/locking.py
index 238fdad..c597514 100644
--- a/nfs4.1/locking.py
+++ b/nfs4.1/locking.py
@@ -33,7 +33,7 @@ def _collect_acq_data(suffix=""):
         def wrapper(self):
             suf = ("" if not suffix else "_%s" % suffix)
             print("ACQUIRE%s tried for lock %s" % (suf.upper(), self.name))
-            t = threading.currentThread()
+            t = threading.current_thread()
             try:
                 t.locks[self.name] = "waiting%s" % suf
             except AttributeError:
@@ -50,7 +50,7 @@ def _collect_rel_data(suffix=""):
         def wrapper(self, *args, **kwargs):
             suf = ("" if not suffix else "_%s" % suffix)
             print("RELEASE%s lock %s" % (suf.upper(), self.name))
-            t = threading.currentThread()
+            t = threading.current_thread()
             t.locks[self.name] = "released%s" % suf
             release(self, *args, **kwargs)
         return wrapper
@@ -139,7 +139,7 @@ class _RWLock(object):
         if notify and self._read_lock == 0:
             # We really want to only wake one write thread, but there
             # might be read threads waiting too.
-            self._cond.notifyAll()
+            self._cond.notify_all()
         elif self._read_lock < 0:
             raise ValueError("Unmatched release")
 
@@ -159,7 +159,7 @@ class _RWLock(object):
         self._write_count -= 1
         self._write_lock.release()
         # Must always notify, since might be write-lockers waiting
-        self._cond.notifyAll()
+        self._cond.notify_all()
 
 class _RWLockVerbose(_RWLock):
     """
diff --git a/nfs4.1/nfs4state.py b/nfs4.1/nfs4state.py
index 6b4cc81..afc19f0 100644
--- a/nfs4.1/nfs4state.py
+++ b/nfs4.1/nfs4state.py
@@ -558,7 +558,7 @@ class StateTableEntry(object):
         with self._private_lock:
             self.read_count -= 1
             if self.read_count + self.write_count == 0:
-                self._private_lock.notifyAll()
+                self._private_lock.notify_all()
 
     def mark_writing(self):
         with self._private_lock:
@@ -568,7 +568,7 @@ class StateTableEntry(object):
         with self._private_lock:
             self.write_count -= 1
             if self.write_count + self.write_count == 0:
-                self._private_lock.notifyAll()
+                self._private_lock.notify_all()
 
     def wait_until_unused(self):
         # Only call this if holding self.lock
diff --git a/nfs4.1/server41tests/st_create_session.py b/nfs4.1/server41tests/st_create_session.py
index 4316644..f382918 100644
--- a/nfs4.1/server41tests/st_create_session.py
+++ b/nfs4.1/server41tests/st_create_session.py
@@ -349,7 +349,7 @@ def testCallbackProgram(t, env):
         c = env.c1.new_client(env.testname(t))
         sess = c.create_session(prog=transient)
         cb_occurred.wait(10)
-        if not cb_occurred.isSet():
+        if not cb_occurred.is_set():
             fail("No CB_NULL sent")
         if cb_occurred.prog != transient:
             fail("Expected cb progam 0x%x, got 0x%x" %
@@ -378,7 +378,7 @@ def testCallbackVersion(t, env):
         c = env.c1.new_client(env.testname(t))
         sess = c.create_session(prog=transient)
         cb_occurred.wait(10)
-        if not cb_occurred.isSet():
+        if not cb_occurred.is_set():
             fail("No CB_NULL sent")
         if not (cb_occurred.low <= cb_occurred.vers <= cb_occurred.hi):
             fail("Expected cb version between %i and %i, got %i" %
diff --git a/rpc/rpc.py b/rpc/rpc.py
index 3621c8e..da59bf1 100644
--- a/rpc/rpc.py
+++ b/rpc/rpc.py
@@ -148,7 +148,7 @@ class DeferredData(object):
     def wait(self, timeout=300):
         """Wait for data to be filled in"""
         self._filled.wait(timeout)
-        if not self._filled.isSet():
+        if not self._filled.is_set():
             raise RPCTimeout
         if self._exception is not None:
             raise self._exception
-- 
2.41.0


[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux