Skip to content

Commit fb4bda9

Browse files
committed
add destroy instance function
Adding a destroy instance function to stub to force invalidate the shared ptr.
1 parent 38fb91a commit fb4bda9

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/pb_stub.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,12 @@ Stub::GetOrCreateInstance()
10851085
return stub_instance;
10861086
}
10871087

1088+
void
1089+
Stub::DestroyInstance()
1090+
{
1091+
stub_instance.reset();
1092+
}
1093+
10881094
void
10891095
Stub::LaunchStubToParentQueueMonitor()
10901096
{
@@ -2135,7 +2141,7 @@ main(int argc, char** argv)
21352141
catch (const PythonBackendException& pb_exception) {
21362142
LOG_INFO << "Failed to preinitialize Python stub: " << pb_exception.what();
21372143
logger.reset();
2138-
stub.reset();
2144+
Stub::DestroyInstance();
21392145
exit(1);
21402146
}
21412147

@@ -2180,6 +2186,7 @@ main(int argc, char** argv)
21802186

21812187
// Destroy stub and exit.
21822188
logger.reset();
2189+
Stub::DestroyInstance();
21832190
exit(1);
21842191
}
21852192
}
@@ -2212,7 +2219,7 @@ main(int argc, char** argv)
22122219
// this process will no longer hold the GIL lock and destruction of the stub
22132220
// will result in segfault.
22142221
logger.reset();
2215-
stub.reset();
2222+
Stub::DestroyInstance();
22162223

22172224
return 0;
22182225
}

src/pb_stub.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class Stub {
9898
Stub() : stub_to_parent_thread_(false), parent_to_stub_thread_(false){};
9999
static std::shared_ptr<Stub> GetOrCreateInstance();
100100

101+
static void DestroyInstance();
102+
101103
/// Instantiate a new Python backend Stub.
102104
void Instantiate(
103105
int64_t shm_growth_size, int64_t shm_default_size,

0 commit comments

Comments
 (0)