From 97eabc11377d8106ef76fa516c6a036a382f4d29 Mon Sep 17 00:00:00 2001 From: Ruda Porto Filgueiras Date: Thu, 11 Oct 2018 15:53:16 +0200 Subject: [PATCH] Added alternative way to limit max number of logs when running in pypy since sys.getsizeof raises TypeError. --- .travis.yml | 2 +- logzio/sender.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b87bef..844b60c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: env: TOXENV=py35 - python: 3.6 env: TOXENV=py36 - - python: pypy2.7 + - python: pypy env: TOXENV=pypy - python: pypy3.5 env: TOXENV=pypy3 diff --git a/logzio/sender.py b/logzio/sender.py index 7b51d53..64cc4bd 100644 --- a/logzio/sender.py +++ b/logzio/sender.py @@ -156,7 +156,12 @@ class LogzioSender: current_size = 0 while not self.queue.empty(): current_log = self.queue.get() - current_size += sys.getsizeof(current_log) + try: + current_size += sys.getsizeof(current_log) + except TypeError: + # pypy do not support sys.getsizeof + current_size += len(current_log) * 4 + logs_list.append(current_log) if current_size >= MAX_BULK_SIZE_IN_BYTES: break