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

On Raspberry Pi 4B, calling Microphone() resource in a subprocess triggers a Segmentation Fault after the subprocess ends. #756

Open
1478540 opened this issue May 19, 2024 · 0 comments

Comments

@1478540
Copy link

1478540 commented May 19, 2024

Steps to reproduce

  1. I attempted to utilize the SpeechRecognition library on a Raspberry Pi to develop a speech recognition project. Whenever I call the Microphone() resource within a subprocess (whether it's a static method or an instance), the program crashes immediately after the subprocess ends(Or crashes after encountering time.sleep() in the main function), triggering a segmentation fault.(Furthermore, the Python interpreter did not provide any stack trace, only the word 'Segmentation fault'. I am not certain if it is an error reported by the Python interpreter.) However, if I only capture data using Microphone() in the main thread and process the data in a subprocess, there are no issues.
    This issue is suspected to be related to the Raspberry Pi hardware and the operating system, as it only occurs when running on a Raspberry Pi. Running the same code segment on a personal computer with the Windows operating system does not result in any errors (with the same Python version and libraries).

  2. Detailed code

     import time
     import threading
     import speech_recognition as sr
     
     def threaded_test1():
     
         print(sr.Microphone.list_microphone_names())       
         time.sleep(5)
     
     def threaded_test2(source):
         with source as s:
             pass
         time.sleep(5)
     
     if __name__ == '__main__':
         m = sr.Microphone() 
     
     #"Both thread test1 and thread test2 trigger a segmentation fault
         sub_thread = threading.Thread(target=threaded_test1)
     #     sub_thread = threading.Thread(target=threaded_test2,args=(m,))
         
         sub_thread.start()
         sub_thread.join()
    
         print("test")
         time.sleep(1)
         print("over")
    
  3. Screenshot of the error(Although the error message includes warnings about ALSA, the same warnings are also present when the program runs normally. Therefore, I don't believe they are related to the ALSA warnings.)

屏幕截图 2024-05-19 165557

Expected behaviour

The program just needs to end correctly.

Actual behaviour

When the program runs to the end of the subprocess that calls the Microphone resource, if the subsequent code in the main thread contains the time.sleep() function, it will crash when it runs to the time.sleep() function, not executing subsequent code, and printing "Segmentation fault" on the screen. (If the subsequent code in the main thread does not contain time.sleep(), it will still trigger a Segmentation fault after the entire program finishes running.)

The stack trace results and thread information from debugging with GDB.(Python interpreter did not provide any stack trace)

Thread 9 "python" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb4ad8440 (LWP 29397)]
0xb0df2b68 in ?? ()
(gdb) backtrace
#0  0xb0df2b68 in ?? ()
#1  0xb6f7f164 in __nptl_deallocate_tsd () at pthread_create.c:301
#2  0xb6f7f310 in start_thread (arg=0xb4ad8440) at pthread_create.c:488
#3  0xb6e12208 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:73 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) info threads
  Id   Target Id                                        Frame 
  1    Thread 0xb6ff7980 (LWP 29352) "python"           0x000bcca0 in ?? ()
* 9    Thread 0xb4ad8440 (LWP 29397) "python" (Exiting) 0xb0df2b68 in ?? ()

System information

My system is <Raspbian GNU/Linux 11>.

My Python version is <Python 3.9.2>.

My SpeechRecognition library version is <3.10.4>.

My PyAudio library version is < 0.2.14>

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

1 participant