Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ERROR:asyncio:Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)" followed by "soundfile.LibsndfileError: System error." #17

Open
CircleCly opened this issue Sep 28, 2023 · 1 comment

Comments

@CircleCly
Copy link

CircleCly commented Sep 28, 2023

Hi,

I tried installing vampnet on my Windows 11 machine. I was able to launch the app using the gradio UI, but when I use the example audio file and click on "Vamp", I first see the following error message:

Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None)>
Traceback (most recent call last):
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
    self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

and then after a few seconds I see

Traceback (most recent call last):
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\gradio\queueing.py", line 388, in call_prediction
    output = await route_utils.call_process_api(
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\gradio\route_utils.py", line 216, in call_process_api
    output = await app.get_blocks().process_api(
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\gradio\blocks.py", line 1555, in process_api
    result = await self.call_function(
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\gradio\blocks.py", line 1193, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\gradio\utils.py", line 654, in wrapper
    response = f(*args, **kwargs)
  File "D:\UserFiles\Academics\Berkeley\fa23\Research\WAM\vampnet\app.py", line 185, in vamp
    return _vamp(data, return_mask=True)
  File "D:\UserFiles\Academics\Berkeley\fa23\Research\WAM\vampnet\app.py", line 102, in _vamp
    mask, pmask.onset_mask(sig, z, interface, width=data[onset_mask_width])
  File "D:\UserFiles\Academics\Berkeley\fa23\Research\WAM\vampnet\vampnet\mask.py", line 201, in onset_mask
    sig.write(f.name)
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\audiotools\core\audio_signal.py", line 602, in write
    soundfile.write(str(audio_path), self.audio_data[0].numpy().T, self.sample_rate)
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\soundfile.py", line 343, in write
    with SoundFile(file, 'w', samplerate, channels,
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\soundfile.py", line 658, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "D:\UserFiles\Programming\Anaconda\envs\vampnet\lib\site-packages\soundfile.py", line 1216, in _open
    raise LibsndfileError(err, prefix="Error opening {0!r}: ".format(self.name))
soundfile.LibsndfileError: Error opening 'C:\\Users\\circl\\AppData\\Local\\Temp\\tmptukdvdkr.wav': System error.

and an error occurs on the website interface. What could be causing this issue?

@hugofloresgarcia
Copy link
Owner

Hmm, this looks a bit like the issue in #12, since there seems to be an issue with my approach to temporary files on Windows. Could you try the fix mentioned in #12?

this could be it: https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file

looks like we're trying to open the file twice: once when NamedTemporaryFile() is created, and another in sig.write.

This solution from stackoverflow could work, you could give it a try!

import os
import tempfile


class CustomNamedTemporaryFile:
    """
    This custom implementation is needed because of the following limitation of tempfile.NamedTemporaryFile:

    > Whether the name can be used to open the file a second time, while the named temporary file is still open,
    > varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).
    """
    def __init__(self, mode='wb', delete=True):
        self._mode = mode
        self._delete = delete

    def __enter__(self):
        # Generate a random temporary file name
        file_name = os.path.join(tempfile.gettempdir(), os.urandom(24).hex())
        # Ensure the file is created
        open(file_name, "x").close()
        # Open the file in the given mode
        self._tempFile = open(file_name, self._mode)
        return self._tempFile

    def __exit__(self, exc_type, exc_val, exc_tb):
        self._tempFile.close()
        if self._delete:
            os.remove(self._tempFile.name)
            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants