[Twisted-Python] Handling application initialization synchronously

David david at silveregg.co.jp
Mon Jun 20 03:00:38 EDT 2011


Hi,

	I was wondering what's the recommended way to initialize a "complex" 
twisted application. Typically, let's say I have an application which 
needs to create a couple of "heavy" objects, each of which may create 
mysql db/tables:

class MyApplication(object):
     def __init__(self):
         # object1 and object2 may need to interact with MySQL,
         # and object2 assumes that object1 is completely initialized
         object1 = SomeClass1()
         object2 = SomeClass2()

Writing this kind of code asynchronously seems very tedious. My current 
solution is to use non-twisted, blocking API, but there may be a more 
elegant solution ? My main issue with using blocking API is that I 
sometimes have to write the same kind of code twice (one blocking, one 
non blocking).

cheers,

David



More information about the Twisted-Python mailing list