Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pip/_vendor/tenacity/nap.py: 64%

11 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:48 +0000

1# Copyright 2016 Étienne Bersac 

2# Copyright 2016 Julien Danjou 

3# Copyright 2016 Joshua Harlow 

4# Copyright 2013-2014 Ray Holder 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); 

7# you may not use this file except in compliance with the License. 

8# You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

15# See the License for the specific language governing permissions and 

16# limitations under the License. 

17 

18import time 

19import typing 

20 

21if typing.TYPE_CHECKING: 

22 import threading 

23 

24 

25def sleep(seconds: float) -> None: 

26 """ 

27 Sleep strategy that delays execution for a given number of seconds. 

28 

29 This is the default strategy, and may be mocked out for unit testing. 

30 """ 

31 time.sleep(seconds) 

32 

33 

34class sleep_using_event: 

35 """Sleep strategy that waits on an event to be set.""" 

36 

37 def __init__(self, event: "threading.Event") -> None: 

38 self.event = event 

39 

40 def __call__(self, timeout: typing.Optional[float]) -> None: 

41 # NOTE(harlowja): this may *not* actually wait for timeout 

42 # seconds if the event is set (ie this may eject out early). 

43 self.event.wait(timeout=timeout)