0

运行以下:

import imageio

class vidrdf:
    def __init__(self, vidfile):
        self.vid = imageio.get_reader(vidfile,  'ffmpeg')

vidfile = 'movie.mov'
rdfobj = vidrdf(vidfile)

我得到:

Fatal Python error: could not acquire lock for <_io.BufferedReader name=8> at interpreter shutdown, possibly due to daemon threads

Thread 0x00007fd2dc2a8700 (most recent call first):
  File “/path/miniconda3/envs/flower/lib/python3.7/site-packages/imageio_ffmpeg/_parsing.py", line 61 in run
  File "miniconda3/envs/flower/lib/python3.7/threading.py", line 926 in _bootstrap_inner
  File “/path/miniconda3/envs/flower/lib/python3.7/threading.py", line 890 in _bootstrap

Current thread 0x00007fd2f0bb9700 (most recent call first):
  File “/path/miniconda3/envs/flower/lib/python3.7/subprocess.py", line 1704 in _communicate
  File “/path/miniconda3/envs/flower/lib/python3.7/subprocess.py", line 939 in communicate
  File “/path/miniconda3/envs/flower/lib/python3.7/site-packages/imageio_ffmpeg/_io.py", line 193 in read_frames
  File “/path/miniconda3/envs/flower/lib/python3.7/site-packages/imageio/plugins/ffmpeg.py", line 342 in _close
  File “/path/miniconda3/envs/flower/lib/python3.7/site-packages/imageio/core/format.py", line 252 in close
  File “/path/miniconda3/envs/flower/lib/python3.7/site-packages/imageio/core/format.py", line 241 in __del__
Aborted (core dumped)

如果我尝试,它不会发生:

import imageio

class vidrdf:
    def __init__(self, vidfile):
        self.vid = imageio.get_reader(vidfile,  'ffmpeg')

vidfile = 'movie.mov'
vidrdf(vidfile)

或者

import imageio

class vidrdf:
    def __init__(self, vidfile):
        vid = imageio.get_reader(vidfile,  'ffmpeg')

vidfile = 'movie.mov'
rdfobj = vidrdf(vidfile)

所以这显然是复制对象的问题。我搜索了守护线程,但由于我直接使用 imageio,我无法弄清楚为什么以及如何解决它。我将不胜感激任何建议。

4

1 回答 1

-1

以下似乎有效,虽然我不知道为什么:

import imageio
import copy

class vidrdf:
    def __init__(self, vidfile):
        vid = imageio.get_reader(vidfile,  'ffmpeg')
        self.vid = copy.copy(vid)


vidfile = 'movie.mov'
rdfobj = vidrdf(vidfile)
于 2019-10-03T19:41:22.500 回答