Skip to content

Commit

Permalink
Give threads unique names (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed May 25, 2020
1 parent 445d7f5 commit 54d116f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,14 +1213,15 @@ class Engine(threading.Thread):
"""

def __init__(self, zc: 'Zeroconf') -> None:
threading.Thread.__init__(self, name='zeroconf-Engine')
threading.Thread.__init__(self)
self.daemon = True
self.zc = zc
self.readers = {} # type: Dict[socket.socket, Listener]
self.timeout = 5
self.condition = threading.Condition()
self.socketpair = socket.socketpair()
self.start()
self.name = "zeroconf-Engine-%s" % (getattr(self, 'native_id', self.ident),)

def run(self) -> None:
while not self.zc.done:
Expand Down Expand Up @@ -1324,10 +1325,11 @@ class Reaper(threading.Thread):
have expired."""

def __init__(self, zc: 'Zeroconf') -> None:
threading.Thread.__init__(self, name='zeroconf-Reaper')
threading.Thread.__init__(self)
self.daemon = True
self.zc = zc
self.start()
self.name = "zeroconf-Reaper_%s" % (getattr(self, 'native_id', self.ident),)

def run(self) -> None:
while True:
Expand Down Expand Up @@ -1411,7 +1413,7 @@ def __init__(
for check_type_ in self.types:
if not check_type_.endswith(service_type_name(check_type_, allow_underscores=True)):
raise BadTypeInNameException
threading.Thread.__init__(self, name='zeroconf-ServiceBrowser_' + '-'.join(self.types))
threading.Thread.__init__(self)
self.daemon = True
self.zc = zc
self.addr = addr
Expand Down Expand Up @@ -1460,6 +1462,10 @@ def on_change(
self.service_state_changed.register_handler(h)

self.start()
self.name = "zeroconf-ServiceBrowser_%s_%s" % (
'-'.join(self.types),
getattr(self, 'native_id', self.ident),
)

@property
def service_state_changed(self) -> SignalRegistrationInterface:
Expand Down

0 comments on commit 54d116f

Please sign in to comment.