bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
680 stars 69 forks source link

RuntimeError on "import soundcard" #31

Closed devzeb closed 5 years ago

devzeb commented 5 years ago

I built an application around this awesome SoundCard library yesterday. Yesterday everything was working properly. Today I started the application again and it throws the following runtime error when I'm importing the package with "import soundcard" (see attached file).

Windows 10 (17134) 64 bit, Python 3.7.0 SoundCard-master branch from 26. September 2018

runtime error on import soundcard.txt

janleskovec commented 5 years ago

If it is of any help: https://msdn.microsoft.com/en-us/library/cc704587.aspx here it says: screenshot from 2018-10-07 13-40-22

devzeb commented 5 years ago

Trying to fix this bug I found out that it only occurs when my application is started with the debugger connected in Pycharm IDE. Running the application without the debugger does not result in that runtime error.

I just created a pull request with a fix for this bug.

Just FYI: The connection to COM was already initialized before because of the debugger, therefore trying to initialize it again fails. I found a thread which describes a similar problem here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/e1bc9fe4-d985-473a-88f7-ef2ed47f77b3/native-c-return-quothresult-0x80010106-cannot-change-thread-mode-after-it-is-set-quot-in?forum=vclanguage According to the answer of Jonathan Caves, we can safely ignore this error, but we have to make sure that we don't try to uninitialize the COM connection afterwards