All of lore.kernel.org
 help / color / mirror / Atom feed
From: Euan Harris <euan.harris@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Euan Harris <euan.harris@citrix.com>, marmarek@invisiblethingslab.com
Subject: [PATCH v3 0/3] python: Add non-blocking Xenstore watch bindings
Date: Fri, 22 Sep 2017 17:21:11 +0100	[thread overview]
Message-ID: <1506097274-130806-1-git-send-email-euan.harris@citrix.com> (raw)

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

             reply	other threads:[~2017-09-22 16:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22 16:21 Euan Harris [this message]
2017-09-22 16:21 ` [PATCH v3 1/3] python: Add binding for xs_fileno() Euan Harris
2017-09-22 17:50   ` Marek Marczykowski-Górecki
2017-09-25  8:40     ` Wei Liu
2017-09-22 16:21 ` [PATCH v3 2/3] python: Extract registered watch search logic from xspy_read_watch() Euan Harris
2017-09-22 16:21 ` [PATCH v3 3/3] python: Add binding for non-blocking xs_check_watch() Euan Harris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1506097274-130806-1-git-send-email-euan.harris@citrix.com \
    --to=euan.harris@citrix.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.