[Twisted-Python] problems with trial and adbapi
![](https://secure.gravatar.com/avatar/21cb878d1bb698685c6307ef819f17f7.jpg?s=120&d=mm&r=g)
Dear Twisters I'm diving into the twisted matrix. Mostly really enjoying it, but sometimes it's a tough ground :) Now i'm trying to set up unittests with trial for a small twisted datastore. the store itself works outside of trial, but strange things happen when running the tests. The first thing I had to learn, is to explicitly start the dbpool with dbpool.start(). Now the tests work sometimes, but sometimes not. I guess the problem has something to do with adbapi's usage of threads and my using of 'deferredResult()' in the tests. can someone help me here? thanks, donfu.
![](https://secure.gravatar.com/avatar/fcc237fd34a8e504f7224df0c58cc0b3.jpg?s=120&d=mm&r=g)
On Sun, 2004-09-19 at 12:44, donfu wrote:
Dear Twisters
I'm diving into the twisted matrix. Mostly really enjoying it, but sometimes it's a tough ground :)
Now i'm trying to set up unittests with trial for a small twisted datastore. the store itself works outside of trial, but strange things happen when running the tests.
The first thing I had to learn, is to explicitly start the dbpool with dbpool.start(). Now the tests work sometimes, but sometimes not. I guess the problem has something to do with adbapi's usage of threads and my using of 'deferredResult()' in the tests.
deferredResult should work just fine, I use it all the time with db-related tests. Are you calling db.close() after the tests are done? dave
![](https://secure.gravatar.com/avatar/21cb878d1bb698685c6307ef819f17f7.jpg?s=120&d=mm&r=g)
deferredResult should work just fine, I use it all the time with db-related tests.
I knew beforehand that the mistake was to be searched on my side :-) I got still much to learn in twistedland.. I forgot to actually return the deferred from the database insert operation, so trial didn't wait for the insert to complete, and the next operation failed. to sum it up: how to shoot yourself in the foot with twisted: you return a deferred to shoot yourself in the foot. when the deferred finally fires (!) your foot is already rotten and garbage collected... ;) donfu.
![](https://secure.gravatar.com/avatar/1b52e0520aff4d30d1eb6f97179da011.jpg?s=120&d=mm&r=g)
Hi, I starts my daemon (server.py) by $twistd -noy server.py In server.py ---------------------------------------- config=Configuration() In somewhere.py, ---------------------------------------- import __main__ config=__main__.config ### Don't work, since __main__ is twistd, not server.py ## how do I get the config in server.py? Thanks. Iap, Singuan
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Fri, 2004-10-01 at 05:40, Iap, Singuan wrote:
In server.py ---------------------------------------- config=Configuration() somewhere.MyObject.addConfig(config)
and then MyObject can access the config.
![](https://secure.gravatar.com/avatar/683b7ed5a3cb97ee82751c9603429fee.jpg?s=120&d=mm&r=g)
but the sys.argv[1:] is going to be twistd's argument, including "-noy","xxx.tac", etc. right? it isn't exactly what he wanted, is it? Yun On Fri, 1 Oct 2004, Itamar Shtull-Trauring wrote:
On Fri, 2004-10-01 at 05:40, Iap, Singuan wrote:
In server.py ---------------------------------------- config=Configuration() somewhere.MyObject.addConfig(config)
and then MyObject can access the config.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
![](https://secure.gravatar.com/avatar/1b52e0520aff4d30d1eb6f97179da011.jpg?s=120&d=mm&r=g)
I have a work-around like this: import __main__ __main__.config=Configuration() And access it in other modules by: import __main__ config=__main__.config But I don't think that is a good idea. There must be more simple and extensible way, I guess. Iap, Singuan -----Original Message----- From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com]On Behalf Of Yun Mao Sent: Friday, October 01, 2004 11:33 PM To: Twisted general discussion Subject: Re: [Twisted-Python] Newbie question: How to reference the "__main__" but the sys.argv[1:] is going to be twistd's argument, including "-noy","xxx.tac", etc. right? it isn't exactly what he wanted, is it? Yun On Fri, 1 Oct 2004, Itamar Shtull-Trauring wrote:
On Fri, 2004-10-01 at 05:40, Iap, Singuan wrote:
In server.py ---------------------------------------- config=Configuration() somewhere.MyObject.addConfig(config)
and then MyObject can access the config.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
![](https://secure.gravatar.com/avatar/b174cc623da9f3f971301ff2ca31c58a.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just use a singleton design for your Configuration class class Configuration: class __impl: def __init__(self): # do your stuff here # __instance = __impl() def __getattr__(self,attr): return getattr(self.__instance,attr) def __setattr__(self,attr,value): return setattr(self.__instance, attr, value) whenever you instanciate Configuration the inner __impl instance will always be the same. Maybe I missed something above - just look up the singleton design in the python cookbook (activestate.com) Hope that helps UC On Sunday 03 October 2004 07:16 pm, Iap, Singuan wrote:
I have a work-around like this:
import __main__ __main__.config=Configuration()
And access it in other modules by:
import __main__ config=__main__.config
But I don't think that is a good idea. There must be more simple and extensible way, I guess.
Iap, Singuan
-----Original Message----- From: twisted-python-bounces@twistedmatrix.com [mailto:twisted-python-bounces@twistedmatrix.com]On Behalf Of Yun Mao Sent: Friday, October 01, 2004 11:33 PM To: Twisted general discussion Subject: Re: [Twisted-Python] Newbie question: How to reference the "__main__"
but the sys.argv[1:] is going to be twistd's argument, including "-noy","xxx.tac", etc. right? it isn't exactly what he wanted, is it?
Yun
On Fri, 1 Oct 2004, Itamar Shtull-Trauring wrote:
On Fri, 2004-10-01 at 05:40, Iap, Singuan wrote:
In server.py ---------------------------------------- config=Configuration()
somewhere.MyObject.addConfig(config)
and then MyObject can access the config.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
- -- UC - -- Open Source Solutions 4U, LLC 2570 Fleetwood Drive Phone: +1 650 872 2425 San Bruno, CA 94066 Cell: +1 650 302 2405 United States Fax: +1 650 872 2417 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBYLVtjqGXBvRToM4RAlLWAKDSfoSU0vgN5WC0jc1R4EWkhCcEtgCg01DW XdOI9yXBfld26J//pdFjBY0= =Svl5 -----END PGP SIGNATURE-----
![](https://secure.gravatar.com/avatar/683b7ed5a3cb97ee82751c9603429fee.jpg?s=120&d=mm&r=g)
Dear Twisted folks, I'm very happy to annouce a beta release of DHARMA project. DHARMA (Distributed Home Agent For Robust Mobile Access) is a research project focusing on providing robust mobile network connectivity. It creates an end-to-end session layer on top of transport layer to provide robust access, transparently mask of unexpected network failures and network interface change. You can suspend/resume your TCP connection with little efforts. DHARMA supports legacy TCP applications with proxy technology. When end-to-end deployment is not available, DHARMA intelligently select the proxy (Home agent) for you from more than 200 nodes all over the world to minimize the routing overhead. The DHARMA core is heavily based on twisted python, and has almost the same abstraction of TCP operations, such as connectSession, listenSession, etc. DHARMA also has a Web-based interface which is built on top of Nevow 0.2. The detailed information is available at http://dharma.cis.upenn.edu Want to have 200 proxies all over the planet for you? Send us a mail to get an account for free. :) Cheers, Yun
participants (6)
-
Dave Peticolas
-
donfu
-
Iap, Singuan
-
Itamar Shtull-Trauring
-
Uwe C. Schroeder
-
Yun Mao