pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

pendulum.parse memory leak

Open meehand opened this issue 1 year ago • 1 comments

  • [x] I am on the latest Pendulum version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • Ubuntu 20.04 -2.1.0 - 2.1.2

Issue

There is a memory leak if pendulum.parse() throws an exception. This started in 2.1.0 and has persisted to 2.1.2.

Leak in 2.1.0 and not 2.0.5:

import pendulum
import psutil

for index in range(1000000):
    try:
        pendulum.parse("FAIL")
    except Exception:
        pass

    if index % 1000 == 0:
        print(f"iteration {index} memory usage {psutil.Process().memory_full_info().rss / 1024} kb")

No leak:

import pendulum
import psutil

for index in range(1000000):
    try:
        pendulum.parse("2021-04-08 14:23:30")
    except Exception:
        pass

    if index % 1000 == 0:
        print(f"iteration {index} memory usage {psutil.Process().memory_full_info().rss / 1024} kb")

meehand avatar Jul 14 '23 21:07 meehand

This bug has been fixed in #563, however, the latest pypi release 2.1.2 is three year ago. And the C extension has been rewritten in Rust, anyway ... it is fixed in master branch ...

xzmeng avatar Sep 19 '23 09:09 xzmeng