diff --git a/gunicorn/config.py b/gunicorn/config.py index 79662e4c..52215b56 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -103,18 +103,20 @@ class Config(object): def worker_class_str(self): uri = self.settings['worker_class'].get() - # are we using a threaded worker? - is_sync = uri.endswith('SyncWorker') or uri == 'sync' - if is_sync and self.threads > 1: - return "gthread" - return uri + if isinstance(uri, str): + # are we using a threaded worker? + is_sync = uri.endswith('SyncWorker') or uri == 'sync' + if is_sync and self.threads > 1: + return "gthread" + return uri + return uri.__name__ @property def worker_class(self): uri = self.settings['worker_class'].get() # are we using a threaded worker? - is_sync = uri.endswith('SyncWorker') or uri == 'sync' + is_sync = isinstance(uri, str) and (uri.endswith('SyncWorker') or uri == 'sync') if is_sync and self.threads > 1: uri = "gunicorn.workers.gthread.ThreadWorker" diff --git a/tests/test_config.py b/tests/test_config.py index c094f6a2..f0ab392c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -13,6 +13,7 @@ from gunicorn import config from gunicorn.app.base import Application from gunicorn.app.wsgiapp import WSGIApplication from gunicorn.errors import ConfigError +from gunicorn.util import load_class from gunicorn.workers.sync import SyncWorker from gunicorn import glogging from gunicorn.instrument import statsd @@ -55,6 +56,10 @@ class NoConfigApp(Application): pass +class CustomWorker(SyncWorker): + pass + + class WSGIApp(WSGIApplication): def __init__(self): super().__init__("no_usage", prog="gunicorn_test") @@ -63,6 +68,18 @@ class WSGIApp(WSGIApplication): pass +def test_worker_class(): + + c = config.Config() + c.set("worker_class", CustomWorker) + assert c.worker_class == CustomWorker + + try: + assert isinstance(load_class(c.worker_class), object) + except AttributeError: + pytest.fail("'load_class doesn't support type class argument'") + + def test_defaults(): c = config.Config() for s in config.KNOWN_SETTINGS: