Skip to content

Resolve Python 3.10 threading deprecation warnings #2576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Coming in build 311, as yet unreleased
* Fixed `TypeError: cannot unpack non-iterable NoneType object` when registering an axscript client ScriptItem (#2513, @Avasam)
* Fixed a memory leak when SafeArrays are used as out parameters (@the-snork)
* Fixed dispatch handling for properties (@the-snork)
* Resolved a handful of deprecation warnings (#2567, #2576, @Avasam)
* The following classes now produce a valid `eval` string representation when calling `repr`: (#2573, @Avasam)
* `pywin.tools.browser.HLIPythonObject`
* `win32com.server.exception.COMException`
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/dialogs/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def ThreadedStatusProgressDialog(title, msg="", maxticks=100):
# event - so use a dumb strategy
end_time = time.time() + 10
while time.time() < end_time:
if t.createdEvent.isSet():
if t.createdEvent.is_set():
break
win32ui.PumpWaitingMessages()
time.sleep(0.1)
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/demos/excelRTDServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def OnServerStart(self):
self.ticker.start()

def OnServerTerminate(self):
if not self.ticker.finished.isSet():
if not self.ticker.finished.is_set():
self.ticker.cancel() # Cancel our wake-up thread. Excel has killed us.

def Update(self):
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/test/testMSOfficeEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _WaitForFinish(ob, timeout):
break
pythoncom.PumpWaitingMessages()
stopEvent.wait(0.2)
if stopEvent.isSet():
if stopEvent.is_set():
stopEvent.clear()
break
try:
Expand Down
12 changes: 8 additions & 4 deletions com/win32com/test/testMarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ def BeginThreadsSimpleMarshal(self, numThreads):
pythoncom.IID_IDispatch, interp._oleobj_
)
t = threading.Thread(
target=self._testInterpInThread, args=(hEvent, interpStream)
target=self._testInterpInThread,
args=(hEvent, interpStream),
daemon=True, # so errors don't cause shutdown hang
)
t.setDaemon(1) # so errors don't cause shutdown hang
t.start()
threads.append(t)
interp = None
Expand All @@ -100,8 +101,11 @@ def BeginThreadsFastMarshal(self, numThreads):
threads = []
for i in range(numThreads):
hEvent = win32event.CreateEvent(None, 0, 0, None)
t = threading.Thread(target=self._testInterpInThread, args=(hEvent, interp))
t.setDaemon(1) # so errors don't cause shutdown hang
t = threading.Thread(
target=self._testInterpInThread,
args=(hEvent, interp),
daemon=True, # so errors don't cause shutdown hang
)
t.start()
events.append(hEvent)
threads.append(t)
Expand Down
10 changes: 6 additions & 4 deletions isapi/threaded_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def __init__(self, extension, io_req_port):
self.running = False
self.io_req_port = io_req_port
self.extension = extension
threading.Thread.__init__(self)
# We wait 15 seconds for a thread to terminate, but if it fails to,
# we don't want the process to hang at exit waiting for it...
self.setDaemon(True)
threading.Thread.__init__(
self,
# We wait 15 seconds for a thread to terminate, but if it fails to,
# we don't want the process to hang at exit waiting for it...
daemon=True,
)

def run(self):
self.running = True
Expand Down
9 changes: 5 additions & 4 deletions win32/test/test_win32file.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@ def testCompletionPortsNonQueued(self, test_overlapped_death=0):
win32file.CreateIoCompletionPort(handle, port, 1, 0)

t = threading.Thread(
target=self._IOCPServerThread, args=(handle, port, test_overlapped_death)
target=self._IOCPServerThread,
args=(handle, port, test_overlapped_death),
daemon=True, # avoid hanging entire test suite on failure.
)
t.setDaemon(True) # avoid hanging entire test suite on failure.
t.start()
try:
time.sleep(0.1) # let thread do its thing.
Expand Down Expand Up @@ -530,7 +531,7 @@ def testAcceptEx(self):
t = threading.Thread(target=self.acceptWorker, args=(port, running, stopped))
t.start()
running.wait(2)
if not running.isSet():
if not running.is_set():
self.fail("AcceptEx Worker thread failed to start")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", port))
Expand All @@ -548,7 +549,7 @@ def testAcceptEx(self):
self.assertEqual(got, b"hello")
# thread should have stopped
stopped.wait(2)
if not stopped.isSet():
if not stopped.is_set():
self.fail("AcceptEx Worker thread failed to successfully stop")


Expand Down
8 changes: 4 additions & 4 deletions win32/test/test_win32pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def testCallNamedPipe(self):
)
self.assertEqual(got, b"bar\0foo")
event.wait(5)
self.assertTrue(event.isSet(), "Pipe server thread didn't terminate")
self.assertTrue(event.is_set(), "Pipe server thread didn't terminate")

def testTransactNamedPipeBlocking(self):
event = threading.Event()
Expand All @@ -82,7 +82,7 @@ def testTransactNamedPipeBlocking(self):
hr, got = win32pipe.TransactNamedPipe(hpipe, b"foo\0bar", 1024, None)
self.assertEqual(got, b"bar\0foo")
event.wait(5)
self.assertTrue(event.isSet(), "Pipe server thread didn't terminate")
self.assertTrue(event.is_set(), "Pipe server thread didn't terminate")

def testTransactNamedPipeBlockingBuffer(self):
# Like testTransactNamedPipeBlocking, but a pre-allocated buffer is
Expand Down Expand Up @@ -110,7 +110,7 @@ def testTransactNamedPipeBlockingBuffer(self):
hr, got = win32pipe.TransactNamedPipe(hpipe, b"foo\0bar", buffer, None)
self.assertEqual(got, b"bar\0foo")
event.wait(5)
self.assertTrue(event.isSet(), "Pipe server thread didn't terminate")
self.assertTrue(event.is_set(), "Pipe server thread didn't terminate")

def testTransactNamedPipeAsync(self):
event = threading.Event()
Expand Down Expand Up @@ -141,7 +141,7 @@ def testTransactNamedPipeAsync(self):
got = buffer[:nbytes]
self.assertEqual(got, b"bar\0foo")
event.wait(5)
self.assertTrue(event.isSet(), "Pipe server thread didn't terminate")
self.assertTrue(event.is_set(), "Pipe server thread didn't terminate")


if __name__ == "__main__":
Expand Down