Giter Site home page Giter Site logo

Comments (6)

mmomtchev avatar mmomtchev commented on June 12, 2024 1

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.

mmomtchev avatar mmomtchev commented on June 12, 2024 1
--- 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.

smoores-dev avatar smoores-dev commented on June 12, 2024

😞 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.

smoores-dev avatar smoores-dev commented on June 12, 2024

Thanks so much, I will give this a shot! I really appreciate it

from pymport.

smoores-dev avatar smoores-dev commented on June 12, 2024

This is working perfectly; thanks again!

from pymport.

mmomtchev avatar mmomtchev commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.