mirror of https://github.com/caronc/apprise
refactor: don't spin up a thread pool for a single notification (#846)
parent
3a2af45e4d
commit
2057107590
|
@ -583,10 +583,16 @@ class Apprise:
|
||||||
Process a list of notify() calls in parallel and synchronously.
|
Process a list of notify() calls in parallel and synchronously.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
n_calls = len(servers_kwargs)
|
||||||
|
|
||||||
# 0-length case
|
# 0-length case
|
||||||
if not servers_kwargs:
|
if n_calls == 0:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# There's no need to use a thread pool for just a single notification
|
||||||
|
if n_calls == 1:
|
||||||
|
return Apprise._notify_sequential(servers_kwargs[0])
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
logger.info(
|
logger.info(
|
||||||
'Notifying %d service(s) with threads.', len(servers_kwargs))
|
'Notifying %d service(s) with threads.', len(servers_kwargs))
|
||||||
|
@ -619,10 +625,16 @@ class Apprise:
|
||||||
Process a list of async_notify() calls in parallel and asynchronously.
|
Process a list of async_notify() calls in parallel and asynchronously.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
n_calls = len(servers_kwargs)
|
||||||
|
|
||||||
# 0-length case
|
# 0-length case
|
||||||
if not servers_kwargs:
|
if n_calls == 0:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# (Unlike with the thread pool, we don't optimize for the single-
|
||||||
|
# notification case because asyncio can do useful work while waiting
|
||||||
|
# for that thread to complete)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
logger.info(
|
logger.info(
|
||||||
'Notifying %d service(s) asynchronously.', len(servers_kwargs))
|
'Notifying %d service(s) asynchronously.', len(servers_kwargs))
|
||||||
|
|
|
@ -1866,8 +1866,8 @@ def test_apprise_async_mode(mock_threadpool, mock_gather, mock_post, tmpdir):
|
||||||
# Send 1 Notification Syncronously, the other Asyncronously
|
# Send 1 Notification Syncronously, the other Asyncronously
|
||||||
assert a.notify("a mixed batch") is True
|
assert a.notify("a mixed batch") is True
|
||||||
|
|
||||||
# Verify our thread pool was created
|
# Verify we didn't use a thread pool for a single notification
|
||||||
assert mock_threadpool.call_count == 1
|
assert mock_threadpool.call_count == 0
|
||||||
mock_threadpool.reset_mock()
|
mock_threadpool.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue