Calling np.fft.irfft simultaneously in multiple threads prevents handling of SIGINT
See original GitHub issueWhen running np.fft.irfft
or np.fft.irfft2
simultaneously in multiple threads, it messes up something with the handling of SIGINT for the entire Python process. I even tried using the signal
module to register a SIGINT handler separately. After starting the threads, whether they complete successfully or not, the process can no longer handle SIGINT.
Reproducing code example:
Running forever, can’t CTRL-C:
import threading
import numpy as np
import time
def task(lock, done):
while not done.is_set():
# Try using the lock and see SIGINT handling restored
#with lock:
np.fft.irfft(np.array(range(10000)))
print("Task done")
threads = []
done_event = threading.Event()
lock = threading.Lock()
for i in range(10):
thread = threading.Thread(target=task, args=(lock, done_event))
threads.append(thread)
thread.start()
print("All tasks started")
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("Keyboard interrupt!")
print("Shutting down")
done_event.set()
for thread in threads:
thread.join()
print("Shutdown successful")
Even weirder - can’t CTRL-C even after the threads are finished:
import threading
import numpy as np
import time
def task(lock, done):
for i in range(100):
if done.is_set():
break
# Try using the lock and see SIGINT handling restored
#with lock:
np.fft.irfft(np.array(range(10000)))
print("Task done")
threads = []
done_event = threading.Event()
lock = threading.Lock()
for i in range(10):
thread = threading.Thread(target=task, args=(lock, done_event))
threads.append(thread)
thread.start()
print("All tasks started")
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("Keyboard interrupt!")
print("Shutting down")
done_event.set()
for thread in threads:
thread.join()
print("Shutdown successful")
Numpy/Python version information:
1.15.1 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
EDIT: Running on Ubuntu 16.04
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
numpy.fft.irfft — NumPy v1.24 Manual
numpy.fft.irfft#. fft.irfft(a, n=None, axis=-1, norm=None)[source]#. Computes the inverse of rfft . This function computes the inverse of the ...
Read more >Python - prevent child threads from being affected from SIGINT ...
The child process inherits a copy of the diverted SIGINT handler. After creating the child process, you restore SIGINT handling by calling ......
Read more >ipcf.ipynb - Christoph Gohlke
CuPy is an implementation of a NumPy-compatible multi-dimensional array on CUDA. To run the FFT based circular correlation function on a GPU, we....
Read more >Fourier Transforms With scipy.fft: Python Signal Processing
Creating a Signal; Mixing Audio Signals; Using the Fast Fourier Transform (FFT) ... together than those of the low-frequency sine wave since they...
Read more >Learning SciPy for Numerical and Scientific Computing
He has also contributed code to various Python and R projects. ... Python, NumPy, SciPy, and matplotlib as a programming environment for scientific....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing, we removed the sigint handling from fft, its just not worth the trouble anymore.
I’m not sure what the plans for future
numpy
releases are, but if inclusion of C++ modules is on the table, it may be worth switchingnumpy
toscipy
’s implementation ofpocketfft
. The speedups are considerable, and the interface code is simpler.