[pypy-svn] r52556 - pypy/dist/pypy/module/select

arigo at codespeak.net arigo at codespeak.net
Sat Mar 15 12:11:30 CET 2008


Author: arigo
Date: Sat Mar 15 12:11:29 2008
New Revision: 52556

Modified:
   pypy/dist/pypy/module/select/app_select.py
   pypy/dist/pypy/module/select/interp_select.py
Log:
Accept float arguments to poll.poll().


Modified: pypy/dist/pypy/module/select/app_select.py
==============================================================================
--- pypy/dist/pypy/module/select/app_select.py	(original)
+++ pypy/dist/pypy/module/select/app_select.py	Sat Mar 15 12:11:29 2008
@@ -59,7 +59,7 @@
         if (not hasattr(timeout, '__int__') and
             not hasattr(timeout, '__float__')):
             raise TypeError('timeout must be a float or None')
-        ret = dict(p.poll(int(float(timeout) * 1000)))
+        ret = dict(p.poll(float(timeout) * 1000.0))
     else:
         ret = dict(p.poll())
 

Modified: pypy/dist/pypy/module/select/interp_select.py
==============================================================================
--- pypy/dist/pypy/module/select/interp_select.py	(original)
+++ pypy/dist/pypy/module/select/interp_select.py	Sat Mar 15 12:11:29 2008
@@ -1,3 +1,4 @@
+import math
 from pypy.interpreter.typedef import TypeDef
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.gateway import W_Root, ObjSpace, interp2app
@@ -53,7 +54,14 @@
         if space.is_w(w_timeout, space.w_None):
             timeout = -1
         else:
-            timeout = space.int_w(w_timeout)
+            timeout = space.float_w(w_timeout)
+            # round non-integral floats upwards (in theory, with timeout=2.5
+            # we should wait at least 2.5ms, so 2ms is not enough)
+            try:
+                timeout = int(math.ceil(timeout))
+            except (OverflowError, ValueError):
+                raise OperationError(space.w_ValueError,
+                                     space.wrap("math range error"))
 
         try:
             retval = rpoll.poll(self.fddict, timeout)



More information about the Pypy-commit mailing list