sdispater / pendulum

Python datetimes made easy
https://pendulum.eustace.io
MIT License
6.18k stars 381 forks source link

pendulum.parse memory leak #720

Open meehand opened 1 year ago

meehand commented 1 year ago

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")
xzmeng commented 11 months ago

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 ...