Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
fe075e7b
Commit
fe075e7b
authored
Dec 16, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear some of our thread state after a fork()
parent
aadf86a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
0 deletions
+69
-0
src/core/threading.cpp
src/core/threading.cpp
+17
-0
src/runtime/capi.cpp
src/runtime/capi.cpp
+10
-0
src/runtime/import.cpp
src/runtime/import.cpp
+4
-0
test/tests/fork.py
test/tests/fork.py
+38
-0
No files found.
src/core/threading.cpp
View file @
fe075e7b
...
...
@@ -358,6 +358,23 @@ void finishMainThread() {
// TODO maybe this is the place to wait for non-daemon threads?
}
extern
"C"
void
PyEval_ReInitThreads
()
{
pthread_t
current_thread
=
pthread_self
();
assert
(
current_threads
.
count
(
pthread_self
()));
auto
it
=
current_threads
.
begin
();
while
(
it
!=
current_threads
.
end
())
{
if
(
it
->
second
->
pthread_id
==
current_thread
)
{
++
it
;
}
else
{
it
=
current_threads
.
erase
(
it
);
}
}
// TODO we should clean up all created PerThreadSets, such as the one used in the heap for thread-local-caches.
}
// For the "AllowThreads" regions, let's save the thread state at the beginning of the region.
// This means that the thread won't get interrupted by the signals we would otherwise need to
// send to get the GC roots.
...
...
src/runtime/capi.cpp
View file @
fe075e7b
...
...
@@ -923,6 +923,16 @@ extern "C" void PyOS_AfterFork(void) {
// - change the definition of the main thread to the current thread
// - call threading._after_fork
// Also see PyEval_ReInitThreads
// Should we disable finalizers after a fork?
// In CPython, I think all garbage from other threads will never be freed and
// their destructors never run. I think for us, we will presumably collect it
// and run the finalizers. It's probably just safer to run no finalizers?
// Our handling right now is pretty minimal... you better just call exec().
PyEval_ReInitThreads
();
_PyImport_ReInitLock
();
}
extern
"C"
{
...
...
src/runtime/import.cpp
View file @
fe075e7b
...
...
@@ -201,6 +201,10 @@ extern "C" int _PyImport_ReleaseLock() {
return
1
;
}
extern
"C"
void
_PyImport_ReInitLock
()
{
// TODO: currently no import lock!
}
extern
"C"
PyObject
*
PyImport_ImportModuleNoBlock
(
const
char
*
name
)
{
Py_FatalError
(
"unimplemented"
);
}
...
...
test/tests/fork.py
0 → 100644
View file @
fe075e7b
# skip-if: True
from
thread
import
start_new_thread
import
time
import
os
counter
=
0
def
daemon_thread
():
global
counter
while
True
:
for
i
in
xrange
(
100
):
counter
+=
1
time
.
sleep
(
0.0
)
start_new_thread
(
daemon_thread
,
())
while
counter
<
100
:
time
.
sleep
(
0.01
)
def
forceCollection
():
for
i
in
xrange
(
100
):
[
None
]
*
128000
pid
=
os
.
fork
()
if
pid
:
print
"parent"
r
=
os
.
waitpid
(
pid
,
0
)
print
r
[
1
]
print
os
.
WIFSIGNALED
(
r
[
1
]),
os
.
WTERMSIG
(
r
[
1
])
assert
os
.
WIFEXITED
(
r
[
1
])
assert
os
.
WEXITSTATUS
(
r
[
1
])
==
0
print
"parent waking up"
forceCollection
()
else
:
print
"child"
forceCollection
()
print
"child exiting successfully"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment