Message 342804 - Python tracker

Message342804

Author pierreglaser
Recipients pierreglaser, vstinner
Date 2019-05-18.17:31:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558200712.2.0.569454302704.issue36950@roundup.psfhosted.org>
In-reply-to
Content
Lib/test/test_asyncio/utils.py defines a similar helper:

def run_until(loop, pred, timeout=30):
    deadline = time.monotonic() + timeout
    while not pred():
        if timeout is not None:
            timeout = deadline - time.monotonic()
            if timeout <= 0:
                raise futures.TimeoutError()
        loop.run_until_complete(tasks.sleep(0.001))

If we trim the ``loop`` usage, we have a rather simple helper can be used to rewrite a decent number of tests, such as:

- _test_multiprocessing.py _TestBarrier._test_reset_f
- _test_multiprocessing.py _TestPoolWorkerLifetime.test_pool_worker_lifetime
- _test_multiprocessing.py TestSyncManagerTypes.test_wait_proc_exit
- fork_wait. ForkWait.test_wait
- test_concurrent_futures.py FailingInitializerMixin.test_initializer
- test_fork1.py ForkTest.waitimpl
- test_logging.py HandlerTests.test_post_fork_child_no_deadlock
- test_os. Win32KillTests._kill
- test_signal.py StressTest.test_stress_delivery_dependent
- test_signal.py StressTest.test_stress_delivery_simulatenous
- test_wait4.py Wait4Test.wait_impl

As well as some top-level commands in:
- test_multiprocessing_main_handling.py some top level instructions
- subprocessdata/sigchlild_ignore.py
- support/__init__.py


I also witnessed some slightly more complex patterns that does not easily fit into the asyncio helper:

# eintr_tester.py FNTREINTLTest._lock
while True:  # synchronize the subprocess
    dt = time.monotonic() - start_time
    if dt > 60.0:
	raise Exception("failed to sync child in %.1f sec" %
dt)
    try:
	lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
	lock_func(f, fcntl.LOCK_UN)
	time.sleep(0.01)
    except BlockingIOError:
                        break

Which is also (IMO) the case for the lines quoted by Victor.

However, such more complex structures do not seem to appear that often, so sticking to run_until and moving it to test.support.script_helper may be enough.
History
Date User Action Args
2019-05-18 17:31:52pierreglasersetrecipients: + pierreglaser, vstinner
2019-05-18 17:31:52pierreglasersetmessageid: <1558200712.2.0.569454302704.issue36950@roundup.psfhosted.org>
2019-05-18 17:31:52pierreglaserlinkissue36950 messages
2019-05-18 17:31:51pierreglasercreate