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

certain numpy code causes arepl to crash without giving any crash indicator #127

Open
Almenon opened this issue Oct 13, 2018 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@Almenon
Copy link
Owner

Almenon commented Oct 13, 2018

import numpy as np
arr = np.array([str(i) for i in range(3)], dtype=np.object)
dtype = arr.dtype
shape = arr.shape
buf = arr.tobytes()
del arr
arr = np.ndarray(buffer=buf, dtype=dtype, shape=shape).copy()

This code causes arepl to hang indefinitely without giving any visual indicator that it crashed.

Opening up the dev console I see the following error:

 ERR process exited with code 3221225477: Error: process exited with code 3221225477
	at terminateIfNeeded (C:\Users\Almenon\.vscode\extensions\almenon.arepl-1.0.2\node_modules\python-shell\index.js:124:27)
	at ChildProcess.<anonymous> (C:\Users\Almenon\.vscode\extensions\almenon.arepl-1.0.2\node_modules\python-shell\index.js:113:13)
	at emitTwo (events.js:126:13)
	at ChildProcess.emit (events.js:214:7)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
@Almenon Almenon self-assigned this Oct 13, 2018
@Almenon Almenon added the bug Something isn't working label Oct 13, 2018
@Almenon
Copy link
Owner Author

Almenon commented Oct 13, 2018

I wrap excec in a try/catch BaseException, which is like the king 👑 of all try/catches. It will catch every possible exception no matter what. So I was confused as to why the segmentation fault generated by the numpy code didn't get caught by my kingly catch.

But apparently a segmentation fault is a signal (SIGSEGV) and signals ARE NOT caught by normal try/catches, as they are not technically exceptions. (even though they will happily crash your program just the same 💀)

In order to catch a signal you have to register a signal handler like so:

import os
import signal

def sig_handler(signum, frame):
    print("segfault")
signal.signal(signal.SIGSEGV, sig_handler)

os.kill(os.getpid(), signal.SIGSEGV)

live demo: https://repl.it/@almenon/signal-handler-py3

This works great if you are on ubuntu .... not so great if you are on windows.
In fact, this does not work at all on windows!

@Almenon
Copy link
Owner Author

Almenon commented Oct 16, 2018

upgrading jsonpickle should have solved the issue but the process still crashes :/
I guess I should raise a bug in jsonpickle repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant