tonybaloney / Pyjion

Pyjion - A JIT for Python based upon CoreCLR
https://www.trypyjion.com
MIT License
1.43k stars 59 forks source link

SIGSEGV when using tqdm #487

Open r1cc4rdo opened 2 years ago

r1cc4rdo commented 2 years ago

tqdm is a drop-in progress bar for Python and the command line. The minimal non-working example below

import tqdm
import pyjion
pyjion.enable()

for _ in tqdm.tqdm(range(10)):
    pass

terminates with:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

on a Intel x64 Mac, .NET 6.0 LTS, Python 3.10

tonybaloney commented 2 years ago

thanks for the report. Can you please run it again with python -X dev

r1cc4rdo commented 2 years ago

Here's the trace:

Fatal Python error: Segmentation fault

Thread 0x000070000ac70000 (most recent call first):
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/threading.py", line 324 in wait
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/threading.py", line 600 in wait
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/_monitor.py", line 60 in run
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/threading.py", line 1009 in _bootstrap_inner
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/threading.py", line 966 in _bootstrap

Current thread 0x0000000119fa7600 (most recent call first):
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 240 in __call__
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 1458 in format_dict
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 1150 in __str__
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 1494 in display
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 1346 in refresh
  File "/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/site-packages/tqdm/std.py", line 1109 in __init__
  File "<stdin>", line 1 in <module>

Extension modules: pyjion._pyjion (total: 1)
[1]    71148 segmentation fault  python -X dev
/Users/riccardo/opt/anaconda3/envs/stereo/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

Pyjion version is 1.2.6, installed via pip.

tonybaloney commented 2 years ago

Hm., that function doesn't do anything exotic.

    def __call__(self, x=None):
        """
        Parameters
        ----------
        x  : float
            New value to include in EMA.
        """
        beta = 1 - self.alpha
        if x is not None:
            self.last = self.alpha * x + beta * self.last
            self.calls += 1
        return self.last / (1 - beta ** self.calls) if self.calls else self.last

I'll see if I can reproduce a smaller, isolated failure

tonybaloney commented 2 years ago

I can't reproduce this on Python 3.10.4 and macOS.

What minor version of Python are you using and which version of tqdm is installed?

r1cc4rdo commented 2 years ago
[riccardo:~]$ python -X dev
Python 3.10.0 (default, Nov 10 2021, 11:24:47) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tqdm
>>> tqdm.__version__
'4.62.3'
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=10, micro=0, releaselevel='final', serial=0)

What are yours? So I can test with them as well.

r1cc4rdo commented 2 years ago

Still happens with python 3.10.4, tqdm 4.64.0

(testtqdm) [riccardo:~]$ python -X dev
Python 3.10.4 (main, Mar 31 2022, 03:38:35) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tqdm
>>> import pyjion
>>> pyjion.enable()
True
>>> print(f'{tqdm.__version__=}')
tqdm.__version__='4.64.0'
>>> for _ in tqdm.tqdm(range(10)):
...     pass
...
Fatal Python error: Segmentation fault

Thread 0x0000700008339000 (most recent call first):
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/threading.py", line 324 in wait
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/threading.py", line 600 in wait
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/_monitor.py", line 60 in run
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/threading.py", line 1009 in _bootstrap_inner
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/threading.py", line 966 in _bootstrap

Current thread 0x00000001140c0600 (most recent call first):
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 240 in __call__
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 1473 in format_dict
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 1165 in __str__
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 1509 in display
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 1361 in refresh
  File "/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/site-packages/tqdm/std.py", line 1109 in __init__
  File "<stdin>", line 1 in <module>

Extension modules: pyjion._pyjion (total: 1)
[1]    77690 segmentation fault  python -X dev
/Users/riccardo/opt/anaconda3/envs/testtqdm/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
tonybaloney commented 2 years ago

This is odd. I've even added your sample as a unit test and submitted to CI/CD, it's passing on all platforms.

https://github.com/tonybaloney/Pyjion/pull/491

Can you try the following :

r1cc4rdo commented 2 years ago

SIGSEGV goes away iff level=0.

I tried all three combinations.