PHP 8.3.31
Preview: fail_clearing_run_switches.py Size: 1.23 KB
//opt/hc_python/lib/python3.12/site-packages/greenlet/tests/fail_clearing_run_switches.py

# -*- coding: utf-8 -*-
"""
If we have a run callable passed to the constructor or set as an
attribute, but we don't actually use that (because ``__getattribute__``
or the like interferes), then when we clear callable before beginning
to run, there's an opportunity for Python code to run.

"""
import greenlet

g = None
main = greenlet.getcurrent()

results = []

class RunCallable:

    def __del__(self):
        results.append(('RunCallable', '__del__'))
        main.switch('from RunCallable')


class G(greenlet.greenlet):

    def __getattribute__(self, name):
        if name == 'run':
            results.append(('G.__getattribute__', 'run'))
            return run_func
        return object.__getattribute__(self, name)


def run_func():
    results.append(('run_func', 'enter'))


g = G(RunCallable())
# Try to start G. It will get to the point where it deletes
# its run callable C++ variable in inner_bootstrap. That triggers
# the __del__ method, which switches back to main before g
# actually even starts running.
x = g.switch()
results.append(('main: g.switch()', x))
# In the C++ code, this results in g->g_switch() appearing to return, even though
# it has yet to run.
print('In main with', x, flush=True)
g.switch()
print('RESULTS', results)

Directory Contents

Dirs: 1 × Files: 28

Name Size Perms Modified Actions
- drwxr-xr-x 2026-06-11 06:30:31
Edit Download
1.23 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
985 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
1.92 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
524 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
956 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
1.25 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
817 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
12.32 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
9.34 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
3.09 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
4.71 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
2.85 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
1.21 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
3.63 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
49.31 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
8.17 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
32.29 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
18.79 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
446 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
3.63 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
8.35 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
1.49 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
883 B lrw-r--r-- 2026-06-11 06:30:31
Edit Download
7.07 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
16.92 KB lrwxr-xr-x 2026-06-11 06:30:31
Edit Download
6.56 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download
57.35 KB lrwxr-xr-x 2026-06-11 06:30:31
Edit Download
9.51 KB lrw-r--r-- 2026-06-11 06:30:31
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).