Skip to content

Commit

Permalink
stop extending thread
Browse files Browse the repository at this point in the history
it's just too difficult to get right when also intending to keep a
reference to an event that must be consulted from the parent - opt
insteda to create an objectthat quacks much like a Thread but creates
one internally at a time of its pleasing
  • Loading branch information
albu-diku committed Aug 28, 2024
1 parent e9516e6 commit 4cc3bb9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/support/serversupp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

"""Configuration related details within the test support library."""

import threading
from threading import Thread, Event as ThreadEvent


class ServerWithinThreadExecutor(threading.Thread):
class ServerWithinThreadExecutor:
"""Execute a server within a thread ensuring we are able to
block until it is ready to recieve test requests.
Expand All @@ -38,10 +38,10 @@ class ServerWithinThreadExecutor(threading.Thread):
the server is ready to handle requests."""

def __init__(self, ServerClass, *args, **kwargs):
super(ServerWithinThreadExecutor, self).__init__()
self._serverclass = ServerClass
self._arguments = (args, kwargs)
self._started = threading.Event()
self._started = ThreadEvent()
self._thread = None
self._wrapped = None

def run(self):
Expand All @@ -56,15 +56,20 @@ def run(self):
except Exception as e:
pass

def start(self):
self._thread = Thread(target=self.run)
self._thread.start()

def start_wait_until_ready(self):
self.start()
if not self._started.is_set():
self._started.wait()
self._started.wait()
return self

def stop(self):
self.stop_server()
self.join()
self._wrapped = None
self._thread.join()
self._thread = None

def stop_server(self):
self._wrapped.shutdown()
Expand Down

0 comments on commit 4cc3bb9

Please sign in to comment.