Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_preload fails with PyPy3: AttributeError: module 'resource' has no attribute 'RUSAGE_THREAD' #260

Closed
sbraz opened this issue Oct 5, 2020 · 2 comments

Comments

@sbraz
Copy link

sbraz commented Oct 5, 2020

Affected Operating Systems

  • Linux

Affected py-lmdb Version

git master

py-lmdb Installation Method

setup.py build

Using bundled or distribution-provided LMDB library?

Both

Distribution name and LMDB library version

Gentoo / v0.9.24

Describe Your Problem

Hi, I've noticed that one test fails with PyPy3:

======================================= test session starts ========================================
platform linux -- Python 3.6.9[pypy-7.3.2-final], pytest-6.1.0, py-1.9.0, pluggy-0.13.1 -- /usr/bin/pypy3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/tmp/py-lmdb/.hypothesis/examples')
rootdir: /tmp/py-lmdb
plugins: hypothesis-5.36.1, requests-mock-1.8.0
collected 1 item                                                                                   

tests/cursor_test.py::PreloadTest::test_preload FAILED                                       [100%]

============================================= FAILURES =============================================
_____________________________________ PreloadTest.test_preload _____________________________________

self = <cursor_test.PreloadTest testMethod=test_preload>

    @unittest.skipIf(sys.platform != 'linux', "test only works on Linux")
    def test_preload(self):
        """
        Test that reading just the key doesn't prefault the value contents, but
        reading the data does.
        """
    
        import resource
        self.c.put(B('a'), B('a') * (256 * 1024 * 1024))
        self.txn.commit()
        self.env.close()
        # Just reading the data is obviously going to fault the value in.  The
        # point is to fault it in while the GIL is unlocked.  We use the buffers
        # API so that we're not actually copying the data in.  This doesn't
        # actually show that we're prefaulting with the GIL unlocked, but it
        # does prove we prefault at all, and in 2 correct places.
        self.path, self.env = testlib.temp_env(path=self.path, writemap=True)
        self.txn = self.env.begin(write=True, buffers=True)
        self.c = self.txn.cursor()
>       minflts_before = resource.getrusage(resource.RUSAGE_THREAD)[6]
E       AttributeError: module 'resource' has no attribute 'RUSAGE_THREAD'

tests/cursor_test.py:267: AttributeError
===================================== short test summary info ======================================
FAILED tests/cursor_test.py::PreloadTest::test_preload - AttributeError: module 'resource' has no...
======================================== 1 failed in 0.54s =========================================

Apparently PyPy3's resource doesn't expose a RUSAGE_THREAD attribute. I checked your CI and the test gets skipped on PyPy2 because sys.platform is linux2 (otherwise it would fail there too because the attribute was added to Python 3.2).

@jnwatson
Copy link
Owner

jnwatson commented Oct 6, 2020

Thank you for the info. Do you happen to know an alternative to get the minor fault count?

@jnwatson
Copy link
Owner

jnwatson commented Oct 6, 2020

Dup of #248

@jnwatson jnwatson closed this as completed Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants