Coder Social home page Coder Social logo

Comments (11)

mgeier avatar mgeier commented on July 20, 2024 1

This indeed looks quite curious, and I can reproduce it on Linux, however only if I increase the range of the for loops (I got a segmentation fault with 1280, but maybe it also crashes with lower values).

I don't really know what's happening and I think it shouldn't happen ... but I think I know how to avoid the problem:

In your first example, sd is a local variable that goes out of scope at the end of connect_audio_output(), and I guess at some point the Python interpreter destroys the stream object while the callback is still running or something.

You should assign the stream object as an instance variable of the SamplerBox object, something like this:

self.sd = sounddevice.OutputStream(...)

from python-sounddevice.

theredled avatar theredled commented on July 20, 2024

There probably is still something to fix but THANK YOU THIS WORKAROUND WORKS!

Probably some memory allocation mess between those two big data chunks (stream VS dict)?
Like some rare bug, more likely to happen here because of their sizes.

from python-sounddevice.

mgeier avatar mgeier commented on July 20, 2024

I would consider it a user error if you let an active stream go out of scope, so I don't think I want to "fix" the problem in the sounddevice module.

But this might be helpful to make the error easier to find: #514.
Can you please try if that would give you more information in your case?

from python-sounddevice.

theredled avatar theredled commented on July 20, 2024

I would consider it a user error if you let an active stream go out of scope, so I don't think I want to "fix" the problem in the sounddevice module.

But a Segfault means something has not been properly destroyed, isn't it?

from python-sounddevice.

mgeier avatar mgeier commented on July 20, 2024

A segfault can mean many things, but in this case I guess it means that something has been destroyed (the stream object), but something else (the audio thread) is still trying to access it.

Ideally, a segfault should never happen in pure Python code, even with completely wrong usage of an API, but I think in this case an exception is merited.

As with all resources in Python, you should ideally manage them with a context manager, and if that's not possible, you should make sure to explicitly close the stream object before letting it go out of scope.

Anything else is grossly negligent, and we cannot reasonably avert a segfault, but at least #514 tries to make it easier to diagnose the problem.

from python-sounddevice.

theredled avatar theredled commented on July 20, 2024

I mean that in pure Python (let's say), if you reference an object A in another object B and then destroy the object, reference in B will be automatically set to None. Or if you reference A.method somewhere, A will not be garbage-collected when out of scope.

But I get that it's probably more low-level than that, thus hard and/or unwanted to be changed. Not an expert so I trust you.

Thanks for #514, not sure how to test it so I'll let others do that!

from python-sounddevice.

mgeier avatar mgeier commented on July 20, 2024

Thanks for #514, not sure how to test it

You should create a development installation (https://python-sounddevice.readthedocs.io/en/0.4.6/CONTRIBUTING.html#development-installation), check out the branch from #514, and then try the original situation where you encountered the problem.

so I'll let others do that!

I made #514 as a direct response to your problem, so you are uniquely suited to check if it would help in your situation or not.

I nobody is confirming that #514 would help significantly, I will not merge it.

from python-sounddevice.

mgeier avatar mgeier commented on July 20, 2024

@theredled Can you please confirm if #514 improves the situation for you?

from python-sounddevice.

theredled avatar theredled commented on July 20, 2024

I'm sorry I can't test, for some reason I'm not even obtaining the original errors I was getting.

from python-sounddevice.

mgeier avatar mgeier commented on July 20, 2024

I'm sorry I can't test, for some reason I'm not even obtaining the original errors I was getting.

Did you try increasing the range in the for-loops as I mentioned above?

from python-sounddevice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.