File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -740,6 +740,37 @@ def custom_handler(loop, context):
740
740
self .assertIs (type (_context ['context' ]['exception' ]),
741
741
ZeroDivisionError )
742
742
743
+ def test_big_call_later_timeout (self ):
744
+ OK , NOT_OK = 0 , 0
745
+
746
+ async def sleep (delay_name , delay ):
747
+ nonlocal OK , NOT_OK
748
+ try :
749
+ await asyncio .sleep (delay )
750
+ except asyncio .CancelledError :
751
+ OK += 1
752
+ except Exception :
753
+ NOT_OK += 1
754
+
755
+ async def main ():
756
+ tests = [
757
+ sleep ("infinity" , float ("inf" )),
758
+ sleep ("sys.maxsize" , float (sys .maxsize )),
759
+ sleep ("sys.maxsize" , sys .maxsize ),
760
+ sleep ("2**55" , 2 ** 55 ),
761
+ sleep ("2**54" , 2 ** 54 ),
762
+ ]
763
+ tasks = [self .loop .create_task (test ) for test in tests ]
764
+ await asyncio .sleep (0.1 )
765
+ for task in tasks :
766
+ task .cancel ()
767
+ await task
768
+
769
+ self .loop .run_until_complete (main ())
770
+
771
+ self .assertEqual (OK , 5 )
772
+ self .assertEqual (NOT_OK , 0 )
773
+
743
774
744
775
class TestBaseAIO (_TestBase , AIOTestCase ):
745
776
pass
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ include "errors.pyx"
50
50
cdef:
51
51
int PY37 = PY_VERSION_HEX >= 0x03070000
52
52
int PY36 = PY_VERSION_HEX >= 0x03060000
53
+ uint64_t MAX_SLEEP = 3600 * 24 * 365 * 100
53
54
54
55
55
56
cdef _is_sock_stream(sock_type):
@@ -1271,10 +1272,10 @@ cdef class Loop:
1271
1272
1272
1273
if delay < 0 :
1273
1274
delay = 0
1274
- elif delay == py_inf:
1275
+ elif delay == py_inf or delay > MAX_SLEEP :
1275
1276
# ~100 years sounds like a good approximation of
1276
1277
# infinity for a Python application.
1277
- delay = 3600 * 24 * 365 * 100
1278
+ delay = MAX_SLEEP
1278
1279
1279
1280
when = < uint64_t> round (delay * 1000 )
1280
1281
if not args:
You can’t perform that action at this time.
0 commit comments