This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Segfault on time.sleep
Type: crash Stage:
Components: Interpreter Core Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Omer.Katz, vstinner
Priority: normal Keywords:

Created on 2014-12-02 23:16 by Omer.Katz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg232059 - (view) Author: Omer Katz (Omer.Katz) * Date: 2014-12-02 23:16
I have found what appears to be a segfualt in time.sleep but I'm not sure.
I have verified that the segfualt occurs both on Python 2.7.8 and 3.4.2.

The following program that reproduces the segfault uses my fork of billiard, a replacement for the multiprocessing module that is used by celery.

In order to install: pip install git+https://github.com/thedrow/billiard@topic/dill-with-threads

The program:
from billiard.pool import ThreadPool

p1 = ThreadPool()

class Foo(object):
    def a(self):
        print("a")
        return 1

    def do(self):
        return p1.apply_async(self.a)


foo = Foo()
r = foo.do()

print(r.get())
p1.close()
p1.join()

The output from gdb:
gdb -ex r -q --args python mt_example.py
Reading symbols from python...done.
Starting program: /home/omer/.virtualenvs/billiard/bin/python mt_example.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff31db700 (LWP 2897)]
[New Thread 0x7ffff29da700 (LWP 2898)]
[New Thread 0x7ffff21d9700 (LWP 2899)]
[New Thread 0x7ffff19d8700 (LWP 2900)]
[New Thread 0x7ffff11d7700 (LWP 2901)]
[New Thread 0x7ffff09d6700 (LWP 2902)]
[New Thread 0x7fffdbfff700 (LWP 2903)]

Program received signal SIGTERM, Terminated.
[Switching to Thread 0x7ffff21d9700 (LWP 2899)]
0x00007ffff71dc1c3 in select () at ../sysdeps/unix/syscall-template.S:81
81	../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) bt
#0  0x00007ffff71dc1c3 in select () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007ffff5fd5d5d in floatsleep (secs=<optimized out>) at Modules/timemodule.c:948
#2  time_sleep (self=<optimized out>, args=<optimized out>) at Modules/timemodule.c:206
#3  0x00000000004b658c in call_function (oparg=<optimized out>, pp_stack=0x7ffff21d8540) at Python/ceval.c:4033
#4  PyEval_EvalFrameEx (f=f@entry=0x7ffff463eda8, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#5  0x00000000004b6f6b in PyEval_EvalCodeEx (co=<optimized out>, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, 
    argcount=argcount@entry=4, kws=<optimized out>, kwcount=0, defs=0x7ffff40bab68, defcount=1, closure=0x0) at Python/ceval.c:3265
#6  0x00000000004b5b28 in fast_function (nk=<optimized out>, na=4, n=<optimized out>, pp_stack=0x7ffff21d8730, func=0x7ffff31e2938)
    at Python/ceval.c:4129
#7  call_function (oparg=<optimized out>, pp_stack=0x7ffff21d8730) at Python/ceval.c:4054
#8  PyEval_EvalFrameEx (f=f@entry=0x7fffe8000b50, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#9  0x00000000004b6f6b in PyEval_EvalCodeEx (co=<optimized out>, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, 
    argcount=argcount@entry=1, kws=<optimized out>, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3265
#10 0x00000000004b5b28 in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7ffff21d8920, func=0x7ffff31e28c0)
    at Python/ceval.c:4129
#11 call_function (oparg=<optimized out>, pp_stack=0x7ffff21d8920) at Python/ceval.c:4054
#12 PyEval_EvalFrameEx (f=f@entry=0x7fffe8000910, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#13 0x00000000004b5bc7 in fast_function (nk=<optimized out>, na=1, n=<optimized out>, pp_stack=0x7ffff21d8a70, func=0x7ffff7e55230)
---Type <return> to continue, or q <return> to quit---
    at Python/ceval.c:4119
#14 call_function (oparg=<optimized out>, pp_stack=0x7ffff21d8a70) at Python/ceval.c:4054
#15 PyEval_EvalFrameEx (f=f@entry=0x7ffff31f1210, throwflag=throwflag@entry=0) at Python/ceval.c:2679
#16 0x00000000004b6f6b in PyEval_EvalCodeEx (co=<optimized out>, globals=<optimized out>, locals=locals@entry=0x0, 
    args=args@entry=0x7ffff31dca68, argcount=<optimized out>, kws=kws@entry=0x0, kwcount=kwcount@entry=0, defs=defs@entry=0x0, 
    defcount=defcount@entry=0, closure=0x0) at Python/ceval.c:3265
#17 0x0000000000529e70 in function_call (func=0x7ffff7e55140, arg=0x7ffff31dca50, kw=0x0) at Objects/funcobject.c:526
#18 0x0000000000422f5a in PyObject_Call (func=func@entry=0x7ffff7e55140, arg=arg@entry=0x7ffff31dca50, kw=kw@entry=0x0)
    at Objects/abstract.c:2529
#19 0x000000000042747d in instancemethod_call (func=0x7ffff7e55140, arg=0x7ffff31dca50, kw=0x0) at Objects/classobject.c:2602
#20 0x0000000000422f5a in PyObject_Call (func=func@entry=0x7ffff4636d70, arg=arg@entry=0x7ffff7f93050, kw=<optimized out>)
    at Objects/abstract.c:2529
#21 0x00000000004b07f7 in PyEval_CallObjectWithKeywords (func=0x7ffff4636d70, arg=0x7ffff7f93050, kw=<optimized out>) at Python/ceval.c:3902
#22 0x00000000004fae92 in t_bootstrap (boot_raw=0x8899c0) at ./Modules/threadmodule.c:614
#23 0x00007ffff7bc40a5 in start_thread (arg=0x7ffff21d9700) at pthread_create.c:309
#24 0x00007ffff71e484d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
msg232214 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-05 21:44
> Program received signal SIGTERM, Terminated.

SIGTERM is not a segmentation fault. SIGSEGV is for segmentation faults.
msg232241 - (view) Author: Omer Katz (Omer.Katz) * Date: 2014-12-06 12:33
So why exactly the program terminates on a system call?

2014-12-05 23:44 GMT+02:00 STINNER Victor <report@bugs.python.org>:

>
> STINNER Victor added the comment:
>
> > Program received signal SIGTERM, Terminated.
>
> SIGTERM is not a segmentation fault. SIGSEGV is for segmentation faults.
>
> ----------
> nosy: +haypo
> resolution:  -> not a bug
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue22985>
> _______________________________________
>
msg232247 - (view) Author: Omer Katz (Omer.Katz) * Date: 2014-12-06 16:55
Capturing the signal provides the following traceback:
File "mt_example.py", line 10, in <module>
    p1 = ThreadPool()
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/pool.py", line 1016, in __init__
    self._result_handler.start()
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/pool.py", line 504, in start
    super(PoolThread, self).start(*args, **kwargs)
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/py2/dummy/__init__.py", line 69, in start
    threading.Thread.start(self)
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 750, in start
    self.__started.wait()
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 620, in wait
    self.__cond.wait(timeout)
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 339, in wait
    waiter.acquire()
  File "mt_example.py", line 6, in handler
    print(''.join(traceback.format_stack(frame)))

  File "mt_example.py", line 10, in <module>
    p1 = ThreadPool()
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/pool.py", line 1016, in __init__
    self._result_handler.start()
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/pool.py", line 504, in start
    super(PoolThread, self).start(*args, **kwargs)
  File "/home/omer/.virtualenvs/billiard/lib/python2.7/site-packages/billiard/py2/dummy/__init__.py", line 69, in start
    threading.Thread.start(self)
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 750, in start
    self.__started.wait()
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 620, in wait
    self.__cond.wait(timeout)
  File "/home/omer/.pyenv/versions/2.7.8/lib/python2.7/threading.py", line 339, in wait
    waiter.acquire()

The following code reproduces that traceback every time:
from billiard.pool import ThreadPool
import signal

def handler(signum, frame):
        import traceback
        print(''.join(traceback.format_stack(frame)))

signal.signal(signal.SIGTERM, handler)

p1 = ThreadPool()

class Foo(object):
    def a(self):
        print("a")
        return 1

    def do(self):
        return p1.apply_async(self.a)


foo = Foo()
r = foo.do()

print(r.get())
p1.close()
p1.join()

I'm convinced that there is a bug somewhere and it seems that Python is the source of the bug.
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67174
2014-12-06 16:55:52Omer.Katzsetmessages: + msg232247
2014-12-06 12:33:48Omer.Katzsetmessages: + msg232241
2014-12-05 21:44:09vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg232214

resolution: not a bug
2014-12-02 23:16:34Omer.Katzcreate