[Twisted-Python] having 'from_' factory method with a deferred in it.

Sinan Nalkaya sardok at gmail.com
Wed Dec 9 05:17:51 MST 2015


Hi Everyone,

I am developing a tiny library where you can use your gpio pins (over
sysfs) in twisted way. You may find more about, on
https://github.com/sardok/txgpio.

I am facing with a race condition issue, where certain files are needed to
be created in filesystem, by kernel, in order have the class to finish its
initialization. Which means in twisted jargon, a deferred needs to be
resolved in __init__ (or another method - see below) method in order to
have complete object.

After reading this blog post
http://as.ynchrono.us/2014/12/asynchronous-object-initialization.html by
Jean-Paul, i believe having 'from_' factory method which waits for those
certain files to be created before creating the actual class object is the
better way.

However, i couldn't find a way to wait for a deferred in order to use the
from_ function in the following form (which is the common form for using
from_ factory methods);

obj = sysfs.GPIO.from_unexported_node(*a, **kw)

More or less, i am looking for some thing equivalent of
'asyncio.get_event_loop()'
and 'yield from loop.run_in_executor()' as mentioned in the blog post.

Thanks,
Sinan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20151209/f39bdd5e/attachment.html>


More information about the Twisted-Python mailing list