[Twisted-Python] Cannot pickle <type 'DB'> objects
Hi! I've written a system that consists of a central module, one or more receiver modules and one or more sender modules. Different modules might handle different protocols, and this is one of the reasons I choose twisted as framework. But now I've got a problem I don't know how to solve. One of the sender modules is depending on another package and that package opens a sleepycat database at initialization. Which is not playing nice with mktap. So, now when I use mktap I get an exception with the error code shown on the subject line of this mail. Is there anyway by which I can tell mktap to "forget" about the sleepycat database or ... ? -- Roland
On Mon, 09 Apr 2007 15:21:50 +0200, Roland Hedberg <roland.hedberg@adm.umu.se> wrote:
Hi!
I've written a system that consists of a central module, one or more receiver modules and one or more sender modules.
Different modules might handle different protocols, and this is one of the reasons I choose twisted as framework.
But now I've got a problem I don't know how to solve.
One of the sender modules is depending on another package and that package opens a sleepycat database at initialization.
Which is not playing nice with mktap. So, now when I use mktap I get an exception with the error code shown on the subject line of this mail.
Is there anyway by which I can tell mktap to "forget" about the sleepycat database or ... ?
Two possibilities jump out at me: - Don't invoke the initialization code of that package in makeService, wait until the startService method of the service you create is called, and invoke it then. This will prevent the DB from being opened until the application is actually started (ie, when twistd is run). - Don't use mktap, just use twistd: since Twisted 2.5, these two are roughly equivalent: mktap foo --bar twistd -f foo.tap vs twistd foo --bar The most significant difference being that the latter doesn't create a tap file initially. Jean-Paul
On 01:34 pm, exarkun@divmod.com wrote:
On Mon, 09 Apr 2007 15:21:50 +0200, Roland Hedberg <roland.hedberg@adm.umu.se> wrote:
Is there anyway by which I can tell mktap to "forget" about the sleepycat database or ... ?
Two possibilities jump out at me:
- Don't invoke the initialization code of that package in makeService, wait until the startService method of the service you create is called, and invoke it then. This will prevent the DB from being opened until the application is actually started (ie, when twistd is run).
This has the added advantage of working with the --uid and --gid options of twistd as well. If your objects are created as the service is created, they will be created (and the database opened) as root. You almost always want to wait until the service actually starts up, i.e. until Twisted has already daemonized, already shed privileges, to actually open files and databases.
- Don't use mktap, just use twistd
There is also probably no reason to use mktap for a case like this any more though, and there are no tests to ensure that pickles remain compatible across Twisted or Python versions. Not only are there no automated tests, but as far as I know nobody is still using taps as a method persisting configuration any more, so it is unlikely there is any mechanism for us to notice if pickle compatibility is broken. In other words, you're probably better off taking both of JP's suggestions rather than just one.
participants (3)
-
glyph@divmod.com -
Jean-Paul Calderone -
Roland Hedberg