Too many threads bug in threaded worker. (#334)

* Use a mixin for common test-case code. This way we can have both
a regular channels test-case, and a transaction test-case, too.

* Adding a reference to django-cq.

* Adding the ability to launch a number of workers in threads.
This is to try and help reduce memory consumption.

* Adding a signal for process level worker startups.

* Cleaning up the threaded worker code.

* Use Python 2.7 friendly code.

* Making the runworker command show a little more information
about how many threads are running.

* Moving the worker ready signal into a method in order to support
polymorphic behavior.

* Ugh, I'm an idiot. Was launching the wrong run.

* Adding a call to the workers' `ready` in `runserver`.

* Fixed a bug whereby too many threads were being
used when threaded workers were used.
This commit is contained in:
Luke Hodkinson 2016-09-03 01:02:29 +10:00 committed by Andrew Godwin
parent 0d25860cf2
commit 079558d5b5

View File

@ -59,12 +59,14 @@ class Command(BaseCommand):
self.callback = callback
self.options = options
# Choose an appropriate worker.
worker_kwargs = {}
if self.n_threads == 1:
self.logger.info("Using single-threaded worker.")
worker_cls = Worker
else:
self.logger.info("Using multi-threaded worker, {} thread(s).".format(self.n_threads))
worker_cls = WorkerGroup
worker_kwargs['n_threads'] = self.n_threads
# Run the worker
self.logger.info("Running worker against channel layer %s", self.channel_layer)
try:
@ -73,6 +75,7 @@ class Command(BaseCommand):
callback=self.callback,
only_channels=self.options.get("only_channels", None),
exclude_channels=self.options.get("exclude_channels", None),
**worker_kwargs
)
worker_process_ready.send(sender=worker)
worker.ready()