Title: Python script on startup stucks at import
Type: performance Stage:
Components: Library (Lib) Versions: Python 3.7
Status: pending Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, serge g, vstinner
Priority: normal Keywords:

Created on 2019-04-23 13:04 by serge g, last changed 2021-11-22 21:43 by iritkatriel.

Messages (3)
msg340722 - (view) Author: serge g (serge g) Date: 2019-04-23 13:04
I am not sure if it is python's issue (correct me if this is wrong place for report). But sometimes (probably every 3-4 attempt) when I run script, interpreter just stucks for some time (0.5-3 minutes) and then actually runs the script normally.

To figure out what happens I increased verbosity (python -vv) and actually python hangs on import on this line:

# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/
# /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/__pycache__/scrypt.cpython-37.pyc matches /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/
# code object from '/home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/hazmat/primitives/kdf/__pycache__/scrypt.cpython-37.(pyc'
(here >>>>>) import 'cryptography.hazmat.primitives.kdf.scrypt' # <_frozen_importlib_external.SourceFileLoader object at 0x7f5c6e3c73c8>
import 'cryptography.hazmat.backends.openssl.backend' # <_frozen_importlib_external.SourceFileLoader object at 0x7f5c6c129c88>
import 'cryptography.hazmat.backends.openssl' # <_frozen_importlib_external.SourceFileLoader object at 0x7f5c6d30d240>
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/x509/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/x509/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/x509/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/x509/
# trying /home/2kg/spider/venv/lib/python3.7/site-packages/cryptography/x509/UnsupportedExtension.pyc

I had version 3.5 installed before and didn't notice such issue. Other scripts from my project suffer from this symptom as well.

My configuration is:
debian 9
python 3.7.3 [GCC 6.3.0 20170516] on linux
cryptography module – version 2.6.1
msg340724 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-04-23 13:18
It seems like you are using Linux. Please using strace to trace system calls to see where Python is stuck:

strace -tt -o trace python3

Once you reproduce the issue using strace, attach created "trace" file to this issue. "-tt" adds timestamp with millisecond resolution.
msg406803 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-22 21:43
Serge, are you still having this problem and if so can you provide the traces? If this issue is abandoned I will close it within a couple of weeks.
Date User Action Args
2021-11-22 21:43:56iritkatrielsetstatus: open -> pending
nosy: + iritkatriel
messages: + msg406803

2019-04-23 13:18:36vstinnersetnosy: + vstinner
messages: + msg340724
2019-04-23 13:04:47serge gcreate