twisted

Twisted Socket Send Message Immediately

眉间皱痕 提交于 2019-12-12 18:29:02
问题 I am making an iPhone application that communicates to a Twisted socket and it works great when I have one message to send. However, my issue is I need to send many different bits of information to the app. Here is my code. if numrows == 1: #Did login msg = "%s: Login Credentials Success" % _UDID print msg for c in self.factory.clients: c.message(msg) time.sleep(0.5) for result in results: for i in range(1, 6): msg = "%s:L%d;%s" % (_UDID, i, result[i]) print msg for c in self.factory.clients:

Producing content indefinitely in a separate thread for all connections?

霸气de小男生 提交于 2019-12-12 17:09:38
问题 I have a Twisted project which seeks to essentially rebroadcast collected data over TCP in JSON. I essentially have a USB library which I need to subscribe to and synchronously read in a while loop indefinitely like so: while True: for line in usbDevice.streamData(): data = MyBrandSpankingNewUSBDeviceData(line) # parse the data, convert to JSON output = convertDataToJSON(data) # broadcast the data ... The problem, of course, is the ... . Essentially, I need to start this process as soon as

Periodically call deferToThread

醉酒当歌 提交于 2019-12-12 17:07:05
问题 I have a list of strings and I want to process the strings in a periodic manner. The period of starting processing a new string is 1 second, and it takes 3 seconds to process a string. What I expect to observe is that from the 3rd second on, I will see a new result every second until all the strings are processed. However, what I actually saw was that all the results showed up together when all of them are generated. So the question is, how to modify the code to achieve what I expect to see?

Twisted LoopingCall with blocking function

时光总嘲笑我的痴心妄想 提交于 2019-12-12 17:03:52
问题 I have an application which needs to poll a database for possible configuration changes. The application is a simple xmlrpc server using Twisted. I have experimented using Twisted's LoopingCall to perform the polling, but because LoopingCall runs on the main thread, the call to the db is blocking. So if the db call is slow for some reason, requests to the xmlrpc server have to wait. So I tried running the LoopingCall in a thread and couldn't really get it to work. My question is, should I run

Twisted and enabling command line history

混江龙づ霸主 提交于 2019-12-12 16:46:44
问题 In a previous question of mine I got this answer: Subclass twisted.conch.recvline.HistoricRecvLine instead of twisted.protocols.basic.LineReceiver . keystrokeReceived is one of the several additional protocol callbacks available when you are using a terminal instead of a TCP connection. – Jean-Paul Calderone But what if what to have both terminal and TCP Connection? When I subclass HistoricRecvLine I lose the functionality of the TCP connection? So let's start it from the beginning. My .py

Check if Twisted Server launched with twistd was started successfully

无人久伴 提交于 2019-12-12 13:33:51
问题 I need a reliable way to check if a Twisted-based server, started via twistd (and a TAC-file), was started successfully. It may fail because some network options are setup wrong. Since I cannot access the twistd log (as it is logged to /dev/null, because I don't need the log-clutter twistd produces), I need to find out if the Server was started successfully within a launch-script which wraps the twistd-call. The launch-script is a Bash script like this: #!/usr/bin/bash twistd \ --pidfile

Dynamically reload a class definition in Python

落爺英雄遲暮 提交于 2019-12-12 12:28:17
问题 I've written an IRC bot using Twisted and now I've gotten to the point where I want to be able to dynamically reload functionality. In my main program, I do from bots.google import GoogleBot and I've looked at how to use reload to reload modules , but I still can't figure out how to do dynamic re-importing of classes. So, given a Python class , how do I dynamically reload the class definition? 回答1: Reload is unreliable and has many corner cases where it may fail. It is suitable for reloading

How to use TCP Keepalive with Endpoints in Twisted?

此生再无相见时 提交于 2019-12-12 11:33:53
问题 Twisted does support TCP Keepalive. But I can't find a simple way to set those on endpoints (client and server). What is the best current practice for doing this? 回答1: I can't see a way that you can achieve this from endpoints cleanly via the API. However take a look at the source to twisted.internet.endpoints._WrappingProtocol - you could possibly set your endpoint to use a _WrappingFactory * which callbacks a deferred when the connection is made. At this point transport is set on the

Would twisted be a good choice for building a multi-threaded server?

ε祈祈猫儿з 提交于 2019-12-12 10:52:50
问题 I need to pull from hundreds of pop3 email accounts, and i want to build a robust server to do this. Would twisted be a good choice for this type of project? Right now a simple prototype would be to pull from a single pop3 account, then it would pull from many but it would be a serialized process. I want to create a server that has multiple threads so it can do things at the same time. 回答1: Twisted is an event-driven networking framework written in Python. It builds heavily on asynchronous

Logging SMTP connections with Twisted

若如初见. 提交于 2019-12-12 10:25:13
问题 Python newbie here. I'm writing an SMTP server using Twisted and twisted.mail.smtp. I'd like to log incoming connections and possibly dump them when there are too many concurrent connections. Basically, I want ConsoleMessageDelivery.connectionMade() method to be called in the following, when a new connection is made: class ConsoleMessageDelivery: implements(smtp.IMessageDelivery) def connectionMade(self): # This never gets called def receivedHeader(self, helo, origin, recipients): myHostname,