Message339637
Currently, when the random module is imported, the hashlib module is always imported which loads the OpenSSL library, whereas hashlib is only needed when a Random() instance is created with a string seed.
For example, "rnd = random.Random()" and "rnd = random.Random(12345)" don't need hashlib.
Example on Linux:
$ python3
Python 3.7.2 (default, Mar 21 2019, 10:09:12)
>>> import os, sys
>>> 'hashlib' in sys.modules
False
>>> res=os.system(f"grep ssl /proc/{os.getpid()}/maps")
>>> import random
>>> 'hashlib' in sys.modules
True
>>> res=os.system(f"grep ssl /proc/{os.getpid()}/maps")
7f463ec38000-7f463ec55000 r--p 00000000 00:2a 5791335 /usr/lib64/libssl.so.1.1.1b
7f463ec55000-7f463eca5000 r-xp 0001d000 00:2a 5791335 /usr/lib64/libssl.so.1.1.1b
...
Attached PR only imports hashlib on demand.
Note: I noticed this issue while working on adding OpenSSL 1.1.1 support to Python 3.4 :-) |
|
Date |
User |
Action |
Args |
2019-04-08 13:11:01 | vstinner | set | recipients:
+ vstinner |
2019-04-08 13:11:01 | vstinner | set | messageid: <1554729061.73.0.692414846311.issue36559@roundup.psfhosted.org> |
2019-04-08 13:11:01 | vstinner | link | issue36559 messages |
2019-04-08 13:11:01 | vstinner | create | |
|