Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak #24

Merged
merged 6 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ List methods return all available items at once. For large collections of data u

## Development

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

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

Expand Down
21 changes: 15 additions & 6 deletions bitrix24/bitrix24.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def __init__(
self._retry_after = int(retry_after)
self._verify_ssl = bool(safe)

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

async def _call(
self, method: str, params: Dict[str, Any] = {}, start: int = 0
self, method: str, params: Dict[str, Any] = None, start: int = 0
) -> Dict[str, Any]:
"""Async call a REST method with specified parameters.

Expand All @@ -124,6 +125,8 @@ async def _call(
params (dict): Optional arguments which will be converted to a POST request string
start (int): Offset for pagination
"""
if params is None:
params = {}
params["start"] = start

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

def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict[str, Any]:
def callMethod(self, method: str, params: Dict[str, Any] = None, **kwargs) -> Dict[str, Any]:
"""Call a REST method with specified parameters.

Parameters
Expand All @@ -150,6 +153,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
-------
Returning the REST method response as an array, an object or a scalar
"""

if params is None:
params = {}

if not method:
raise BitrixError("Wrong method name", 400)

Expand All @@ -158,14 +165,16 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
except RuntimeError:
warnings.warn(
"You are using `callMethod` method in a synchronous way. "
"Starting from version 3, this method will be completly asynchronous."
"Starting from version 3, this method will be completely asynchronous."
"Please consider updating your code",
DeprecationWarning,
)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(self._call(method, params or kwargs))
loop.close()
try:
result = loop.run_until_complete(self._call(method, params or kwargs))
finally:
loop.close()
else:
result = asyncio.ensure_future(self._call(method, params or kwargs))
return result
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os import path
from setuptools import find_packages

dir = path.abspath(path.dirname(__file__))
directory = path.abspath(path.dirname(__file__))

setup(
name="bitrix24-rest",
Expand Down Expand Up @@ -36,7 +36,7 @@
author="Akop Kesheshyan",
author_email="[email protected]",
description="Easy way to communicate with bitrix24 portal over REST without OAuth",
long_description=open(path.join(dir, "README.md"), encoding="utf-8").read(),
long_description=open(path.join(directory, "README.md"), encoding="utf-8").read(),
long_description_content_type="text/markdown",
keywords="bitrix24 api rest",
classifiers=[
Expand Down
Loading