This problem has been driving me crazy for a couple of days. I'm hoping someone can shed some light
on this. I have a twisted server its using open-ssl (using certificates) and runs on linux and communicates great with a windows client thats send messages every second.
However when I send data back to the client "sometimes" it doesnt receive the packet and there is no indication of failure at the client whats more I dont see any failure on the twisted server end. Is there any way I can tell what could cause this failure? It just look like the transport.write(data) fails just dont know why it would when receiving works like a charm.
Any help on this would relieve the pain I'm feeling right now.
Hey all -
I've recently started working with the 'mock' library in our trial tests,
and am looking for some best-practice advice. I'm really just starting to
get used to the library, so it might well have functionality that I'm
unaware of or am misusing.
I very quickly ran into a problem where I mistakenly returned a Mock() in
the place of a deferred, causing the asserts in callbacks to not be called,
and for the test to spuriously pass.
A basic example:
d = Mock()
self.assertEqual(res.code, expected) # never called
return d # Mock is truthy, test passes
This occurred where I was mocking some internals of the class under test;
something like the below
A slightly more believable example:
== myclass.py ==
d = self.authenticate()
d.addCallback(foo) # foo never called
d.addErrback(bar) # bar never called
== test_myclass.py ==
self.resource.authenticate = Mock(return_value=Mock())
d = self.resource.some_function
def check_result(res): # never called
return d # test passes
Currently, I'm experimenting with wrapping Mock instantiations by defining
common deferred methods on them in advance; this approach would eventually
lead to extending Mock itself with this functionality.
m = Mock()
def notimpl(*args, **kwargs):
raise NotImplementedError('You treated a Mock like a Deferred!')
m.addCallback = notimpl
m.addErrback = notimpl
m.addBoth = notimpl
m.addCallbacks = notimpl
Another approach might be extending TestCase to check that return values
are always not Mock objects.
Does anyone on the list have experience with this? Obviously, this only
happens when mistakes are made when writing tests, but I'd rather have
confidence that when my tests pass, that they've passed for the right
Another antipattern that I've come across has been:
resource.mymethod = Mock(return_value=defer.succeed(None))
which works fine for tests in which mymethod() is called once, but always
returns the same deferred object if multiple calls are made. What would be
a better approach?
i am fairly new to twisted and try to work my way trough the documentation.
There is a problem I can't find a solution for. Maybe somebody can give me a hint or point me into the right direction.
I am trying to create a TCP server. The client connects to the server, then the server will send multiple commands and binary data to the client. After the data has been send, the connection should stay open.
I subclass "Protocol" to create my protocol.
It seems that after i send data with self.transport.write(data) the last packet will be send with the "FP." flag, what seems to "Finalize" the connection from this end.
Is there a way to force twisted to just "Push" my data, but not to "Finalize" the connection?
I'm porting some code to twisted and got a little stuck. The current
(non-twisted) code connects to a server, gives it some data (a job to
do), gets a job-id and then terminates the connection. Sometime later,
it reconnects and gets the output using the job-id.
I've a factory and protocol set up, with buildProtocol over-riden in the
Factory class to supply some extra data to each Protocol instance when
it's created. This is fine when I submit a job as I can call a factory
function to generate the required data (ie the job to do). My problem is
how to initiate a connection at some point in the future AND pass it
some specific info (ie the job-id) for it to pass to the server.
I start the connections using task.callingLoop and reactor.connectTCP so
my first guess was to add: task.callLater(time, reactor.connectTCP, ...)
to the connectionLost method of my Protocol. However, I cannot see how
to pass in any extra information (ie the job-id) this way? I know I can
store state in the Factory, so I guess I just need to know how to pass
this to a scheduled invocation of the Protocol.
Is anyone able to point me in the right direction here?
Nick Johnson, Applications Developer, EPCC
2407 JCMB, King's Buildings, Mayfield Road, Edinburgh, EH9 3JF
e: Nick.Johnson(a)ed.ac.uk t: 0131 651 3388
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
I have a use case (namely setting the Linux-specific SO_MARK socket
option) where I need to set the socket option after the socket object is
created but before Twisted starts to try and connect.
Is there a clean way to do this? Ideally there would be some sort of
pre-connect function, similar to the preexec_fn for child processes, but
any reasonably clean solution will do.
(By clean I mean "doesn't have me duplicating hundreds of lines of
Twisted code into my own Connector/Port/etc. classes" ;o)
This will be my last report, until the beginning of September. I have,
for many years, been a volunteer at the Edmonton Folk Music
Festival. For the next month, I will be busy setting it up (and then
taking it down, and so will not have time to devote to twisted.
This month, 23 tickets got some attention that they would not have
received without the sponsored development. The result was 5 closed
tickets and 11 other tickets unblocked for other developers to resume
This month, I made a number of improvements to the buildobt:
- Switched most of the buildslaves to use git to checkout the source.
- All the git-using builders merge to trunk, before running tests, so
the tests results reflect the code as it would be merged. In
particular, all the lint steps should now accurately report only
the regressions relative to current trunk of the merged result.
- I added a bunch of new builders on VMs provided by Rackspace
(thanks to Jesse Noller) and the Fedora Project (thanks to
Seth Vidal). These cover all recent versions of Debian, Fedora,
Ubuntu and RHEL. As part of this, I automated the deployment of
buildslaves, (currently only Debian and Fedora derivatives are
This work is made possible by the sponsorship of individuals and
organizations which have donated to the Twisted project, part of the
Software Freedom Conservancy, a not-for-profit organization that helps
promote, improve, and develop open source software. Thanks!
The tickets I reviewed, that have now been closed:
- #5574: Add support for SOCK_DGRAM to IReactorSocket
- #6221: Replace Deprecated Test Case Assertion Methods in twisted.internet
- #6393: Utility function to pretty-format list of things
- #6475: FileAuthority._lookup incorrectly returns AuthoritativeDomainError for non-subdomain names which happen to share the same suffix as the zone (eg the-example.com and example.com)
- #6572: twisted.mail.smtp.sendmail should return a cancellable Deferred
Other tickets I have reviewed:
- #2699: UDP DatagramProtocol reconnecting
- #3926: twisted.positioning -- a better positioning framework
- #4173: WebSocket server support
- #4735: Implement something like ReconnectingClientFactory for endpoints
- #5001: replace call to functions from the string module in twisted.scripts.tap2deb
- #5004: replace call to functions from the string module in web
- #5685: SMTP Client Tutorial should be self-contained
- #6556: LineReceiver rejects lines of length MAX_LENGTH sometimes
- #6557: LineOnlyReceiver doesn't disconnect the transport when it detects an overlarge line
- #6558: LineOnlyReceiver doesn't pass the entire contents of its buffer to lineLengthExceeded()
- #6580: twisted.names.server.DNSServerFactory should query child zones before parent zones
Tickets I have worked on:
- #5513: Detailed documentation on Proxy by adding docstrings to many of the methods.
- #6537: Update coding-standard to reflect that documentation should be sentence per line.
- #6620: Document conventions for writting test assertions.
- #6626: Remove all uses of deferredGenerator.
> On Jul 17, 2013, at 5:04 PM, Jeffrey Ollie <jeff at ocjtech.us> wrote:
> > I know that this has been asked before, but it's been a while and I'm
> > hoping for some good news. Is there a SQL ORM that works well with
> > Twisted and PostgreSQL? In particular I'm hoping to find something
> > that works with txpostgres as that's the library I prefer to access
> > the database with.
> There's bits of one in Calendar Server: <http://trac.calendarserver.org/browser/CalendarServer/trunk/twext/enterpris…> It doesn't use txpostgres, but that's because it relies on adbapi2 (also in calendar server, hopefully to be moved into Twisted at some point).
I've made a thing that has a similar API to txpostgres and will use
txpostgres underneath if it's installed:
I welcome feedback/patches.
- Matt Haggard
(I wasn't on the mailing list when the original message was sent, so
this "reply" may not appear quite correctly)
following up from ticket #6502, I'm looking for recommendations/best
practices for writing unit-tests for AMP-based code.
As described in the ticket, the issue I'm currently facing is that the
AMP implementation is subtly not re-entrant safe and doesn't work with a
synchronous transport, for example this code raises an exception:
I'm starting to think that the most appropriate testing strategy would
be to mock/stub AMP.callRemote (or the protocol class altogether)
instead of trying to use a fake transport.
I want to enable ssl on port 7081 for my python application I'm using this
port for xmlrpc. I have twisted library installed but I'm not getting
exactly how to use it's functions to enable ssl. here is my code.
and at client side:
server_proxy = xmlrpclib.Server("http://localhost:7081",allow_none=True)
and what code should be there at the client side please suggest solution
for that. I also want to do the same thing for java client for the same
please suggest solution for that.