Skip to content

Commit 6c058be

Browse files
authored
Merge pull request #24 from igor-backend/master
fix memory leak
2 parents 87bc71d + 6ea714d commit 6c058be

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ List methods return all available items at once. For large collections of data u
5757

5858
## Development
5959

60-
New contributers and pull requests are welcome. If you have any questions or suggestions, feel free to open an issue.
60+
New contributors and pull requests are welcome. If you have any questions or suggestions, feel free to open an issue.
6161

6262
Code comes with makefile for easy code base management. You can check `make help` for more details.
6363

bitrix24/bitrix24.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def __init__(
4848
self._retry_after = int(retry_after)
4949
self._verify_ssl = bool(safe)
5050

51-
def _prepare_domain(self, domain: str) -> str:
51+
@staticmethod
52+
def _prepare_domain(domain: str) -> str:
5253
"""Normalize user passed domain to a valid one."""
5354
o = urlparse(domain)
5455
if not o.scheme or not o.netloc:
@@ -114,7 +115,7 @@ async def request(self, method: str, params: str = None) -> Dict[str, Any]:
114115
return response
115116

116117
async def _call(
117-
self, method: str, params: Dict[str, Any] = {}, start: int = 0
118+
self, method: str, params: Dict[str, Any] = None, start: int = 0
118119
) -> Dict[str, Any]:
119120
"""Async call a REST method with specified parameters.
120121
@@ -124,6 +125,8 @@ async def _call(
124125
params (dict): Optional arguments which will be converted to a POST request string
125126
start (int): Offset for pagination
126127
"""
128+
if params is None:
129+
params = {}
127130
params["start"] = start
128131

129132
payload = self._prepare_params(params)
@@ -138,7 +141,7 @@ async def _call(
138141
return res["result"] + result
139142
return res["result"]
140143

141-
def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict[str, Any]:
144+
def callMethod(self, method: str, params: Dict[str, Any] = None, **kwargs) -> Dict[str, Any]:
142145
"""Call a REST method with specified parameters.
143146
144147
Parameters
@@ -150,6 +153,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
150153
-------
151154
Returning the REST method response as an array, an object or a scalar
152155
"""
156+
157+
if params is None:
158+
params = {}
159+
153160
if not method:
154161
raise BitrixError("Wrong method name", 400)
155162

@@ -158,14 +165,16 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
158165
except RuntimeError:
159166
warnings.warn(
160167
"You are using `callMethod` method in a synchronous way. "
161-
"Starting from version 3, this method will be completly asynchronous."
168+
"Starting from version 3, this method will be completely asynchronous."
162169
"Please consider updating your code",
163170
DeprecationWarning,
164171
)
165172
loop = asyncio.new_event_loop()
166173
asyncio.set_event_loop(loop)
167-
result = loop.run_until_complete(self._call(method, params or kwargs))
168-
loop.close()
174+
try:
175+
result = loop.run_until_complete(self._call(method, params or kwargs))
176+
finally:
177+
loop.close()
169178
else:
170179
result = asyncio.ensure_future(self._call(method, params or kwargs))
171180
return result

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from os import path
99
from setuptools import find_packages
1010

11-
dir = path.abspath(path.dirname(__file__))
11+
directory = path.abspath(path.dirname(__file__))
1212

1313
setup(
1414
name="bitrix24-rest",
@@ -36,7 +36,7 @@
3636
author="Akop Kesheshyan",
3737
author_email="hello@akop.dev",
3838
description="Easy way to communicate with bitrix24 portal over REST without OAuth",
39-
long_description=open(path.join(dir, "README.md"), encoding="utf-8").read(),
39+
long_description=open(path.join(directory, "README.md"), encoding="utf-8").read(),
4040
long_description_content_type="text/markdown",
4141
keywords="bitrix24 api rest",
4242
classifiers=[

0 commit comments

Comments
 (0)