Comments (6)
Alas, at first glance, there are no solutions without consequences.
terminate
comes while the worker is in Python. When the sleep
call ends - because there is no mechanism that can interrupt a running C++ call - the environment does not exist anymore and Node-API itself aborts because it cannot throw the exception. pymport
does not get a chance to intervene at all.
There is a Node-API switch called NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS
which solves your problem, but as its name goes, it can hide exceptions from you and it seems to be a dangerous options. If you add this #define
, it won't crash - it will silently exit.
It is a compile-time option, so I cannot give you the possibility to set a runtime flag - pymport
must be rebuilt with it. Everything I can do is an installation option.
By the way I highly recommend you to load pymport
in the main thread before using it in worker threads, because otherwise, Node.js will keep loading and unloading the DLL every time a worker thread quits.
from pymport.
--- a/src/pymport.h
+++ b/src/pymport.h
@@ -1,5 +1,6 @@
#pragma once
+#define NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS
#include <map>
#include <list>
#include <set>
from pymport.
😞 That does make sense, thank you for explaining.
Would you be able to give me a little bit more info about that Node-API switch? Rebuilding pymport might be alright, in this specific case, since Storyteller is only distributed as a Docker container. I'm already building node-sqlite3
from source in that same container. I don't think I know how to add the flag, though; are you saying it's something I would actually have to add to a pymport header file, or something?
Thanks for the note about loading pymport into the main thread, that's a good call. In the actual production service, I'm using piscina, and I'm only using a single, persistent worker thread, so the worker module gets cached and startup and I believe only ends up getting loaded one time.
from pymport.
Thanks so much, I will give this a shot! I really appreciate it
from pymport.
This is working perfectly; thanks again!
from pymport.
As you have surely seen from my profile page, I am currently in a middle of a huge extortion involving the French police, corrupt judges, several big tech companies and many major open source projects. In order to intimidate me, people are posting simultaneously in my projects.
from pymport.
Related Issues (20)
- Race condition on macOS with worker_threads
- `pymport` leaks TLS memory when used in a `worker_thread` HOT 2
- Random crash with `worker_threads`
- V8 GC does not know if `PyObject`s grow after initialization
- Background Python operations can block the event loop
- Loading and unloading `pymport` leaks memory HOT 2
- A single `Buffer` argument is incorrectly transformed to Python `kwargs` HOT 2
- Second Interpreter and stdin/out HOT 4
- `pymport` not compatible with Python 3.12
- feat request: Support IPython Kernel HOT 2
- Support multiple subscript operator in proxified PyObjects. HOT 3
- Using the Node.js inspector can lead to a crash HOT 3
- After loading `pymport`, further loading of other binary modules does not work HOT 2
- Don't have the pymport built-in Python environment installed HOT 3
- Installation error HOT 1
- Error when installing build-need package such as auto_gptq HOT 1
- install fails HOT 10
- "libsqlite3.so.0: cannot open shared object file: No such file or directory" HOT 1
- How does it differs from node-calls-python ? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymport.