1. sleep() for half a sec?
- Posted by newphil82 Feb 17, 2015
- 1393 views
Just in case you get this problem??
I wanted to make a VERY QUICK 'blink' in a Windows GUI. Docs suggest fractions OK in 'sleep' but I got: sleep(0.5) type check failure, "t is an integer"
This quick solution worked for me: machine_proc(64, 0.5) 64 is M_SLEEP, but number easier to find!
2. Re: sleep() for half a sec?
- Posted by jimcbrown (admin) Feb 17, 2015
- 1382 views
Just in case you get this problem??
I wanted to make a VERY QUICK 'blink' in a Windows GUI. Docs suggest fractions OK in 'sleep' but I got: sleep(0.5) type check failure, "t is an integer"
This quick solution worked for me: machine_proc(64, 0.5) 64 is M_SLEEP, but number easier to find!
Or use std/os.e for sleep() instead of misc.e
3. Re: sleep() for half a sec?
- Posted by DerekParnell (admin) Feb 17, 2015
- 1352 views
Just in case you get this problem??
I wanted to make a VERY QUICK 'blink' in a Windows GUI. Docs suggest fractions OK in 'sleep' but I got: sleep(0.5) type check failure, "t is an integer"
This quick solution worked for me: machine_proc(64, 0.5) 64 is M_SLEEP, but number easier to find!
If using Win32lib, you can call w32Sleep( x ) where 'x' is in milliseconds.
If just using Windows directly, use the Windows API ...
atom doze = define_c_proc(open_dll("kernel32.dll"), "Sleep",{C_LONG}) c_proc( doze, 500 ) -- sleep for 500 milliseconds.
4. Re: sleep() for half a sec?
- Posted by ghaberek (admin) Feb 17, 2015
- 1369 views
Just in case you get this problem??
I wanted to make a VERY QUICK 'blink' in a Windows GUI. Docs suggest fractions OK in 'sleep' but I got: sleep(0.5) type check failure, "t is an integer"
It looks like you're using the legacy include files.
In Euphoria 3.1, sleep() was defined in misc.e.
-- from misc.e global procedure sleep(integer t) -- go to sleep for t seconds -- allowing (on WIN32 and Linux) other processes to run if t >= 0 then machine_proc(M_SLEEP, t) end if end procedure
But starting with Euphoria 4.0, sleep() was defined in std/os.e.
-- from std/os.e public procedure sleep(atom t) -- go to sleep for t seconds -- allowing other processes to run if t >= 0 then machine_proc(M_SLEEP, t) end if end procedure
Both methods do call the same internal machine function, which is why your trick worked.
Further testing indicates that sleep() in Euphoria 4.0 does provide sub-second resolution.
include misc.e as misc include std/os.e as os atom t0, t1, t2 t0 = time() misc:sleep( 1 ) t1 = time() - t0 t0 = time() os:sleep( 0.1 ) t2 = time() - t0 printf( 1, "misc:sleep(1) = %0.1f sec\n", {t1} ) printf( 1, "os:sleep(0.1) = %0.1f sec\n", {t2} )
misc:sleep(1) = 1.0 sec os:sleep(0.1) = 0.1 sec
In short, make sure you are using the Euphoria 4.0 standard library routines in the std include directory.
-Greg
5. Re: sleep() for half a sec?
- Posted by jimcbrown (admin) Feb 17, 2015
- 1366 views
In short, make sure you are using the Euphoria 4.0 standard library routines in the std include directory.
-Greg
But keep in mind that this only works for 4.0.0 or newer. Older versions did not support subsecond sleeping, even when calling the machine proc directly.
6. Re: sleep() for half a sec?
- Posted by ghaberek (admin) Feb 17, 2015
- 1358 views
In short, make sure you are using the Euphoria 4.0 standard library routines in the std include directory.
But keep in mind that this only works for 4.0.0 or newer. Older versions did not support subsecond sleeping, even when calling the machine proc directly.
I always used this trick to get sub-second sleep() resolution in older versions of Euphoria. Works pretty well.
include misc.e global procedure sleep_ms( atom t ) atom t0 = time() + t while time() < t0 do sleep(0) end while end procedure atom t0, t1 t0 = time() sleep_ms( 0.25 ) t1 = time() - t0 printf( 1, "sleep_ms(0.25) = %0.2f sec\n", {t1} )
sleep_ms(0.25) = 0.25 sec-Greg