[issue35902] Forking from background thread

2019-02-05 Thread Vadim Tsozik


New submission from Vadim Tsozik :

Attached is code sample that forks child process either from main or from 
background thread. Child starts and joins all of its threads except a sleeping 
daemon. If parent forks child from main thread program exits immediately after 
child threads are joined and waitpid is unblocked by SIGCHLD. However if parent 
process happens to fork from main thread everything works correctly and process 
exits immediately without waiting for daemon to sleep for 3600 seconds. I'm 
wondering what is the difference between main and background thread in parent. 
Only one thread survives forking in child and becomes main thread in the child, 
so there should be no differences in the behavior.

Thank you in advance for your help,

--
components: Build
files: threadforkmodel.py
messages: 334886
nosy: vtsozik
priority: normal
severity: normal
status: open
title: Forking from background thread
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: https://bugs.python.org/file48103/threadforkmodel.py

___
Python tracker 
<https://bugs.python.org/issue35902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35902] Forking from background thread

2019-02-05 Thread Vadim Tsozik


Vadim Tsozik  added the comment:

Thank you for your reply. I understand that forking and threads do not mix well 
if developer is not careful and child doesn't clear/reset synchronization 
variables inherited from parent. However this is not the case in provided code 
sample. The answer to my question is probably related to the fact that only 
main thread handles signaling by default in POSIX. But in the provided example 
parent background thread becomes main in the child. In parent it doesn't matter 
if waitpid blocks on main or background thread. The only thing really matters 
if code forks from main or background threads.

--

___
Python tracker 
<https://bugs.python.org/issue35902>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com