twisted

how to send data with twisted protocol via factory

二次信任 提交于 2019-12-18 10:46:45
问题 I'm writing a client implementing a custom protocol, and have a factory for it. My problem is the following: my client has bi-dir communication, and sometimes I want to tell it "send this data". But all I have is the factory object: class MyFactory(ClientFactory): protocol = MyProtocol def __init__(self, recv_callback): self.recv_callback = recv_callback def send_message(self, msg): self.protocol.send_message(msg) So I create a factory and have a factory object, I don't the protocol object.

How do you you run a Twisted application via Python (instead of via Twisted)?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 10:43:09
问题 I am working my way through learning Twisted, and have stumbled across something I'm not sure I'm terribly fond of - the "Twisted Command Prompt". I am fiddling around with Twisted on my Windows machine, and tried running the "Chat" example: from twisted.protocols import basic class MyChat(basic.LineReceiver): def connectionMade(self): print "Got new client!" self.factory.clients.append(self) def connectionLost(self, reason): print "Lost a client!" self.factory.clients.remove(self) def

How to run a program and also execute code when data is received from the network?

折月煮酒 提交于 2019-12-18 09:42:00
问题 I've written a little program in Python that basically does the following: Gets a hotword as input from the user. If it matches the set keyword it continues. After entering the correct hotword the user is asked to enter a command. After the command is read the progam checks a command file to see if there is a command that matches that input If a matching command is found, execute whatever that command says. I'd like to add the ability to execute commands over a network as follows (and learn

Python DeferredList callback reporting success when deferreds raise error

有些话、适合烂在心里 提交于 2019-12-18 09:37:23
问题 I have the following simple script: #!/usr/bin/env python from twisted.internet import defer from twisted.web.client import getPage, reactor def success(results): print 'success' def error(results): print 'error' def finished(results): print 'finished', results tasks = [] d = getPage('thiswontwork').addCallback(success).addErrback(error) tasks.append(d) dl = defer.DeferredList(tasks) dl.addCallback(finished) reactor.run() That produces the following output: error finished [(True, None)] I

Non-blocking file access with Twisted

家住魔仙堡 提交于 2019-12-18 05:27:16
问题 I'm trying to figure out if there is a defacto pattern for file access using twisted. Lots of examples I've looked at (twisted.python.log, twisted.persisted.dirdbm, twisted.web.static) actually don't seem to worry about blocking for file access. It seems like there should be some obvious interface, probably inheriting from abstract.FileDescriptor, that all file access should be going through it as a producer/consumer. Have I missed something or is it just that the primary use for twisted in

Scrapy throws error ReactorNotRestartable when runnning on AWS Lambda

青春壹個敷衍的年華 提交于 2019-12-18 04:25:15
问题 I have deployed a scrapy project which crawls whenever an lambda api requests comes. It runs perfectly for the first api call but later on it fails and throws ReactorNotRestartable error. As far as I can understand the AWS Lambda ecosystem is not killing the process, hence reactor is still present in the memory. The lambda log error is as follows: Traceback (most recent call last): File "/var/task/aws-lambda.py", line 42, in run_company_details_scrapy process.start() File "./lib/scrapy

Why does scrapy throw an error for me when trying to spider and parse a site?

送分小仙女□ 提交于 2019-12-18 03:40:43
问题 The following code class SiteSpider(BaseSpider): name = "some_site.com" allowed_domains = ["some_site.com"] start_urls = [ "some_site.com/something/another/PRODUCT-CATEGORY1_10652_-1__85667", ] rules = ( Rule(SgmlLinkExtractor(allow=('some_site.com/something/another/PRODUCT-CATEGORY_(.*)', ))), # Extract links matching 'item.php' and parse them with the spider's method parse_item Rule(SgmlLinkExtractor(allow=('some_site.com/something/another/PRODUCT-DETAIL(.*)', )), callback="parse_item"), )

TwistedWeb on multicore/multiprocessor

天大地大妈咪最大 提交于 2019-12-17 21:54:14
问题 What techniques are people using to utilize multiple processors/cores when running a TwistedWeb server? Is there a recommended way of doing it? My twisted.web based web service is running on Amazon EC2 instances, which often have multiple CPU cores (8, 16), and the type of work that the service is doing benefits from extra processing power, so i would very much like to use that. I understand that it is possible to use haproxy, squid or a web server, configured as a reverse proxy, in front of

How to write a twisted server that is also a client?

微笑、不失礼 提交于 2019-12-17 15:58:26
问题 How do I create a twisted server that's also a client? I want the reactor to listen while at the same time it can also be use to connect to the same server instance which can also connect and listen. 回答1: Call reactor.listenTCP and reactor.connectTCP . You can have as many different kinds of connections - servers or clients - as you want. For example: from twisted.internet import protocol, reactor from twisted.protocols import basic class SomeServerProtocol(basic.LineReceiver): def

Python twisted: where to start [closed]

倖福魔咒の 提交于 2019-12-17 14:59:38
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I am trying to start learning twisted for socket servers creation. I want to add some useful features (like auth, and maybe some other