Author vstinner
Recipients brett.cannon, rhettinger, vstinner
Date 2019-04-08.20:32:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> In general, we don't do deferred imports unless there is a compelling reason (i.e. it is very slow or it is sometimes unavailable).

While I was working on adding OpenSSL 1.1.1 to Python 3.4, my _hashopenssl module was broken. In that case, "import random" fails with ImportError because of hashlib failures. I was surprised, since random doesn't need hashlib at startup.

I would like to be able to use "import random" even if hashlib is broken. For me, random is a key component, whereas I see hashlib more as optional. (Even if in practice, it should always be available).

> Otherwise, it is a false optimization.

> Could you explain a bit more, Victor, about why you want to avoid importing hashlib and OpenSSL so much?

Well, OpenSSL is not a random tiny library. For example, loading it increases Python RSS of around 2.7 MiB.

Example with script
import os
os.system(f"grep ^VmRSS /proc/{os.getpid()}/status")
import random
os.system(f"grep ^VmRSS /proc/{os.getpid()}/status")

Output without the change on Fedora 29:

VmRSS:	    7396 kB
VmRSS:	   11796 kB  # +4.4 MiB

With the change:

VmRSS:	    7272 kB
VmRSS:	    8988 kB  # +1.7 MiB

Another example is that OpenSSL loads the dynamic library by dependency.

I would prefer to minimize Python footprint if possible.
Date User Action Args
2019-04-08 20:32:55vstinnersetrecipients: + vstinner, brett.cannon, rhettinger
2019-04-08 20:32:55vstinnersetmessageid: <>
2019-04-08 20:32:55vstinnerlinkissue36559 messages
2019-04-08 20:32:55vstinnercreate