decord
decord copied to clipboard
Importing `torch` after importing `decord` causes hanging behavior
I ran into a strange issue where the import order specifically between torch
and decord
can causing hanging behavior.
Concretely, I found that having your imports like this (which could happen by chance or if you use isort
):
import decord
import torch # hangs :(
will cause a hang. However, switching the order of imports fixes the issue:
import torch
import decord
This seems like some issue with the way decord's imports are set up internally, though I'm not sure exactly what would cause this. This is what the trace looks like when it's truly hanging:
>(963): <frozen importlib._bootstrap>(1003): <frozen importlib._bootstrap>(1006): --- modulename: _bootstrap, funcname: _load_unlocked
<frozen importlib._bootstrap>(666): <frozen importlib._bootstrap>(668): <frozen importlib._bootstrap>(674): --- modulename: _bootstrap, funcname: module_from_spec
<frozen importlib._bootstrap>(567): <frozen importlib._bootstrap>(568): <frozen importlib._bootstrap>(571): --- modulename: _bootstrap_external, funcname: create_module
<frozen importlib._bootstrap_external>(1176): <frozen importlib._bootstrap_external>(1177): <frozen importlib._bootstrap_external>(1176): --- modulename: _bootstrap, funcname: _call_with_frames_removed
Steps to reproduce:
- Create conda environment
conda create -p NEW_ENV_PATH python=3.10
conda activate NEW_ENV_PATH
pip install torch decord
- Create interactive python session
- Import decord:
import decord
- Attempt to import torch:
import torch
I found this to be reproducible with the following settings:
>>> torch.__version__
'2.0.0+cu117'
>>> decord.__version__
'0.6.0'
OS: CentOS Linux Version 7 (Core)
Bumping this! I spent a while trying to figure out my script wasn't running, but this was exactly why.
Same issue here
Same issue
See @sailordiary's comment on #186 https://github.com/dmlc/decord/issues/186#issuecomment-1171882325
I found this to be reproducible with the following settings:
@zhanwenchen thanks for the pointer, could you please clarify how that comment addresses this issue? Are you proposing that it's related to the FFmpeg build?
I hit the same issue when using pytorch==2.0.1 and decord==0.6.0 ; Another environment with pytorch==2.2.1 and decord==0.6.0 seems to work though.