Skip to content

Commit faeaa15

Browse files
authored
Fix memory issues with webhooks. (#570)
* Update sync.py * Update async_.py
1 parent b1d9235 commit faeaa15

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

discord/webhook/async_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import asyncio
3030
import json
3131
import re
32+
import weakref
3233

3334
from urllib.parse import quote as urlquote
3435
from typing import Any, Dict, List, Literal, NamedTuple, Optional, TYPE_CHECKING, Tuple, Union, overload
@@ -98,7 +99,7 @@ async def __aexit__(self, type, value, traceback):
9899

99100
class AsyncWebhookAdapter:
100101
def __init__(self):
101-
self._locks: Dict[Any, asyncio.Lock] = {}
102+
self._locks: weakref.WeakValueDictionary = weakref.WeakValueDictionary()
102103

103104
async def request(
104105
self,

discord/webhook/sync.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import json
3737
import time
3838
import re
39+
import weakref
3940

4041
from urllib.parse import quote as urlquote
4142
from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union, overload
@@ -94,7 +95,7 @@ def __exit__(self, type, value, traceback):
9495

9596
class WebhookAdapter:
9697
def __init__(self):
97-
self._locks: Dict[Any, threading.Lock] = {}
98+
self._locks: weakref.WeakValueDictionary = weakref.WeakValueDictionary()
9899

99100
def request(
100101
self,

0 commit comments

Comments
 (0)