Author vstinner
Recipients vstinner
Date 2019-04-08.13:11:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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
>>> res=os.system(f"grep ssl /proc/{os.getpid()}/maps")

>>> import random
>>> 'hashlib' in sys.modules
>>> res=os.system(f"grep ssl /proc/{os.getpid()}/maps")
7f463ec38000-7f463ec55000 r--p 00000000 00:2a 5791335                    /usr/lib64/
7f463ec55000-7f463eca5000 r-xp 0001d000 00:2a 5791335                    /usr/lib64/

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:01vstinnersetrecipients: + vstinner
2019-04-08 13:11:01vstinnersetmessageid: <>
2019-04-08 13:11:01vstinnerlinkissue36559 messages
2019-04-08 13:11:01vstinnercreate