question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling np.fft.irfft simultaneously in multiple threads prevents handling of SIGINT

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
sebergcommented, Jul 17, 2020

Closing, we removed the sigint handling from fft, its just not worth the trouble anymore.

0reactions
mreineckcommented, Jun 8, 2020

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 switching numpy to scipy’s implementation of pocketfft. The speedups are considerable, and the interface code is simpler.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found