I put together this patch after having problems with a application I was
writing where the wall time had to be updated while the application was
running. With the current pynotifier generic notifier code this cause
the application to appear to hang while the dispatch loop catches up.

Using the monotonic clock fixes the issue of the wall clock being
updated. The patch includes a version for linux (tested) and an untested
version for OS X.

Hope this might be useful.

Cheers

Adam
Index: src/pynotifier/nf_generic.py
===================================================================
--- src/pynotifier/nf_generic.py	(revision 4271)
+++ src/pynotifier/nf_generic.py	(working copy)
@@ -68,7 +68,11 @@
 from select import error as select_error
 from time import time, sleep as time_sleep
 import errno, os, sys
-
+try:
+    from kaa._rt import get_monotonic_time as milliseconds
+except:
+    def milliseconds():
+        return int(time() * 1000)
 import socket
 
 # internal packages
@@ -125,7 +129,7 @@
 		__timer_id = 0
 
 	__timers[ __timer_id ] = \
-	[ interval, int( time() * 1000 ) + interval, method ]
+	[ interval, milliseconds() + interval, method ]
 
 	return __timer_id
 
@@ -167,7 +171,7 @@
 		if not sleep:
 			timeout = 0
 		else:
-			now = int( time() * 1000 )
+			now = milliseconds()
 			for interval, timestamp, callback in __timers.values():
 				if not timestamp:
 					# timer is blocked (recursion), ignore it
@@ -211,7 +215,7 @@
 				# timer was unregistered by previous timer, or would
 				# recurse, ignore this timer
 				continue
-			now = int( time() * 1000 )
+			now = milliseconds()
 			if timestamp <= now:
 				# Update timestamp on timer before calling the callback to
 				# prevent infinite recursion in case the callback calls
@@ -224,7 +228,7 @@
 					# Find a moment in the future. If interval is 0, we
 					# just reuse the old timestamp, doesn't matter.
 					if timer[ INTERVAL ]:
-						now = int( time() * 1000 )
+						now = milliseconds()
 						timestamp += timer[ INTERVAL ]
 						while timestamp <= now:
 							timestamp += timer[ INTERVAL ]
Index: setup.py
===================================================================
--- setup.py	(revision 4271)
+++ setup.py	(working copy)
@@ -110,7 +110,18 @@
     else:
         print '- Linux-specific features not being built (inotify, set_process_name)'
 
+    if osname == 'linux':
+        rt_ext = Extension('kaa._rt', ['src/extensions/linux_rt.c'], libraries=['rt'])
+        extensions.append(rt_ext)
+    
+    elif osname == 'darwin':
+        rt_ext = Extension('kaa._rt', ['src/extensions/darwin_rt.c'])
+        extensions.append(rt_ext)
+    
+    else:
+        print '- Not building rt features will resort to using time.time() instead'
 
+
 # call setup
 setup(
     module = 'base',
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to