All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] python: Add non-blocking Xenstore watch bindings
@ 2017-09-21 16:47 Euan Harris
  2017-09-21 16:47 ` [PATCH v2 1/3] python: Add binding for xs_fileno() Euan Harris
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Euan Harris @ 2017-09-21 16:47 UTC (permalink / raw)
  To: xen-devel; +Cc: Euan Harris, marmarek

Expose xs_fileno() and xs_check_watch() to Python.   These functions
make it posible to write event-driven Xenstore clients in Python:

  #!/usr/bin/env python
  
  import xen.lowlevel.xs
  
  import sys
  import errno
  from select import select
  import time
  
  # Connect to XenStore and set watch
  xsh = xen.lowlevel.xs.xs()
  xsh.watch("/foo", "footoken")
  xsh.watch("/bar", "bartoken")
  
  # Start polling loop
  xsfd = xsh.fileno()
  while True:
     readable, writable, exceptional = select([xsfd], [], [xsfd], 1.0)
     print "%d tick" % time.time()
  
     if readable:
         while True:
             watch = xsh.check_watch()
             if not watch:
                 break
             path, token = watch
             print "%d watch fired: path=%s, token=%s" % (time.time(), 
                                                          path, token)
             value = xsh.read("", path)
             print "%d read %s = %s" % (time.time(), path, value)
  
     if exceptional:
         print "select error"
  
The polling loop can be simplified further by wrapping the call to
xsh.check_watch() in a generator, but this is easier to do in Python
than in the C bindings.


Euan Harris (3):
  python: Add binding for xs_fileno()
  python: Extract registered watch search logic from  xspy_read_watch()
  python: Add binding for non-blocking xs_check_watch()

 tools/python/xen/lowlevel/xs/xs.c | 108 ++++++++++++++++++++++++++++++--------
 1 file changed, 85 insertions(+), 23 deletions(-)

-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-21 18:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-21 16:47 [PATCH v2 0/3] python: Add non-blocking Xenstore watch bindings Euan Harris
2017-09-21 16:47 ` [PATCH v2 1/3] python: Add binding for xs_fileno() Euan Harris
2017-09-21 18:04   ` Marek Marczykowski-Górecki
2017-09-21 16:47 ` [PATCH v2 2/3] python: Extract registered watch search logic from xspy_read_watch() Euan Harris
2017-09-21 18:07   ` Marek Marczykowski-Górecki
2017-09-21 16:47 ` [PATCH v2 3/3] python: Add binding for non-blocking xs_check_watch() Euan Harris
2017-09-21 18:09   ` Marek Marczykowski-Górecki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.