Skip to content

Commit

Permalink
release 5.155.22087
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Mar 28, 2022
2 parents 4fcd3c9 + 327170b commit d9382b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
5 changes: 2 additions & 3 deletions mo_threads/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def __init__(self, name, target, *args, **kwargs):
else:
self.parent = Thread.current()
self.parent.add_child(self)
self.please_stop.then(self.start)

def __enter__(self):
return self
Expand Down Expand Up @@ -282,7 +281,6 @@ def _run(self):
if hook:
sys.settrace(hook)

self.please_stop.remove_then(self.start)
self.id = get_ident()
with RegisterThread(self):
try:
Expand Down Expand Up @@ -622,7 +620,8 @@ def start_main_thread():

with ALL_LOCK:
if ALL:
raise Exception("failure")
names = [t.name for k, t in ALL.items()]
raise Exception(f"expecting no threads {names}")

ALL[get_ident()] = MAIN_THREAD

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
name='mo-threads',
packages=["mo_threads"],
url='https://github.com/klahnakoski/mo-threads',
version='5.154.22086',
version='5.155.22087',
zip_safe=False
)
2 changes: 1 addition & 1 deletion setuptools.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@
"name": "mo-threads",
"packages": ["mo_threads"],
"url": "https://github.com/klahnakoski/mo-threads",
"version": "5.154.22086",
"version": "5.155.22087",
"zip_safe": false
}
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def write(self, template, params):
self.lines.append(expand_template(template, params))

def stop(self):
pass
self.lines.append("logger stopped")
30 changes: 5 additions & 25 deletions tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
from __future__ import unicode_literals

from mo_future import text
from mo_json import value2json
from mo_logs import Log
from mo_logs.log_usingNothing import StructuredLogger
from mo_logs.strings import expand_template
from mo_testing.fuzzytestcase import FuzzyTestCase
from mo_times.dates import Date
from mo_times.durations import SECOND
Expand Down Expand Up @@ -191,25 +188,21 @@ def test_start_stopped_thread(self):
We often spawn threads to do work; ensure the thread is at least started,
let the thread decide how to balance please_stop and the work to be done
"""
stop_main_thread()
threads.MAIN_THREAD.stopped.wait()
start_main_thread()
list_log = StructuredLogger_usingList()
old_log, Log.main_log = Log.main_log, list_log
old_log.stop()
done = []

def worker(please_stop):
Log.info("started")
done.append("started")

please_stop = Signal()
please_stop.go()
thread = Thread.run("work", worker, please_stop=please_stop)
thread.stopped.wait()
self.assertIn("started", Log.main_log.lines)
self.assertIn("started", done)

def test_failure_during_wait_for_shutdown(self):
threads.DEBUG = True
threads.MAIN_THREAD.stop()
stop_main_thread()

start_main_thread()
list_log = StructuredLogger_usingList()
old_log, Log.main_log = Log.main_log, list_log
Expand All @@ -225,19 +218,6 @@ def test_failure_during_wait_for_shutdown(self):
self.assertIn("ERROR", list_log.lines[-2])
self.assertEqual(bool(threads.MAIN_THREAD.timers.stopped), True)

start_main_thread()


def bad_worker(please_stop):
raise Exception("bad worker failure")


class StructuredLogger_usingList(StructuredLogger):
def __init__(self):
self.lines = []

def write(self, template, params):
self.lines.append(expand_template(template, params))

def stop(self):
self.lines.append("logger stopped")

0 comments on commit d9382b4

Please sign in to comment.