twisted

stop a twisted reactor after a gatherResults has finished

放肆的年华 提交于 2019-12-07 02:19:25
new to twisted and just trying some deferred stuff out. I have the following code that makes up a list of 100 deferred calls - each waiting a random time and returning a value. That list the prints the results and finally terminates the reactor. However, I'm pretty sure the way I'm stopping the reactor is probably... not great. __author__ = 'Charlie' from twisted.internet import defer, reactor import random def getDummyData(x): """returns a deferred object that will have a value in some random seconds sets up a callLater on the reactor to trgger the callback of d""" d = defer.Deferred() pause

Scrapy: how to debug scrapy lost requests

丶灬走出姿态 提交于 2019-12-07 02:04:06
问题 I have a scrapy spider, but it doesn't return requests sometimes. I've found that by adding log messages before yielding request and after getting response. Spider has iterating over a pages and parsing link for item scrapping on each page. Here is a part of code SampleSpider(BaseSpider): .... def parse_page(self, response): ... request = Request(target_link, callback=self.parse_item_general) request.meta['date_updated'] = date_updated self.log('parse_item_general_send {url}'.format(url

Python Twisted integration with Cmd module

旧城冷巷雨未停 提交于 2019-12-07 01:58:58
问题 I like Python's Twisted and Cmd. I want to use them together. I got some things working, but so far I haven't figured out how to make tab-completion work, because I don't see how to receive tab keypres events right away (without pressing Enter) in Twisted's LineReceiver. Here's my code so far: #!/usr/bin/env python from cmd import Cmd from twisted.internet import reactor from twisted.internet.stdio import StandardIO from twisted.protocols.basic import LineReceiver class CommandProcessor(Cmd):

Twisted spawnProcess, send output of one process to input of another

血红的双手。 提交于 2019-12-07 00:54:29
I am trying to use twisted spawnProcess to replicate the behavior of something like this: cat <input.txt | wc -w This is just an example of two commands, in reality I have my own processes (say python or bash scripts or external programs) where each process reads from stdin and writes to stdout. Just like the above example, I want to pipe stdout from one process to stdin of another, and I want to do this using spawnProcess. I used some hints here: Twisted pipe two processes with spawnProcess but I can't get it to work. It just hangs when reading from stdin on the second spawnProcess protocol.

How do I run twisted from the console?

跟風遠走 提交于 2019-12-06 22:25:31
问题 I'm using Python 3 with Anaconda on Windows 7. I installed Twisted with conda install twisted , and now I'm trying to run twisted (or twistd ?) from the console, but I get this error 'twisted' is not recognized as an internal or external command, operable program or batch file. which makes me think a directory is missing from the path, as in this question. Anaconda is installed in C:\Anaconda3 , but even in C:\Anaconda3\Lib\site-packages\twisted , there isn't a twisted.py or twistd.py file.

Twisted XmlStream: How to connect to events?

烈酒焚心 提交于 2019-12-06 17:00:56
问题 I would like to implement a Twisted server that expects XML requests and sends XML responses in return: <request type='type 01'><content>some request content</content></request> <response type='type 01'><content>some response content</content></response> <request type='type 02'><content>other request content</content></request> <response type='type 02'><content>other response content</content></response> I have created a Twisted client & server before that exchanged simple strings and tried

How to handle connection or download error in Scrapy?

别来无恙 提交于 2019-12-06 16:26:26
I am using the following to check for (internet) connection errors in my spider.py : def start_requests(self): for url in self.start_urls: yield scrapy.Request(url, callback=self.parse, errback=self.handle_error) def handle_error(self, failure): if failure.check(DNSLookupError): # or failure.check(UnknownHostError): request = failure.request self.logger.error('DNSLookupError on: %s', request.url) print("\nDNS Error! Please check your internet connection!\n") elif failure.check(HttpError): response = failure.value.response self.logger.error('HttpError on: %s', response.url) print('\nSpider

网络爬虫之scrapy框架详解

ぐ巨炮叔叔 提交于 2019-12-06 16:11:43
twisted介绍 Twisted是用Python实现的基于事件驱动的网络引擎框架,scrapy正是依赖于twisted, 它是基于事件循环的异步非阻塞网络框架,可以实现爬虫的并发。 twisted是什么以及和requests的区别: request是一个python实现的可以伪造浏览器发送Http请求的模块,它封装了socket发送请求 twisted是基于时间循环的异步非阻塞的网络框架,它也封装了socket发送请求,但是他可以单线程的完成并发请求。 twisted的特点是: 非阻塞:不等待 异步:回调 事件循环:一直循环去检查状态 scrapy的pipeline文件和items文件 这两个文件有什么作用 先看看我们上篇的示例: + View Code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 # -*- coding: utf-8 -*- import scrapy class ChoutiSpider(scrapy.Spider): ''' 爬去抽屉网的帖子信息 ''' name = 'chouti' allowed_domains = [

Python, Call a class function from another class

試著忘記壹切 提交于 2019-12-06 16:09:31
Can you anyone please help me (noob) call the broadcast function from class BroadcastServerFactory in class process , as per attached code I have tried so many methods of call a function from another class, but no solution import time, sys from apscheduler.scheduler import Scheduler import threading import socket from twisted.internet import reactor from twisted.python import log from twisted.web.server import Site from twisted.web.static import File from autobahn.websocket import WebSocketServerFactory, \ WebSocketServerProtocol, \ listenWS class process(threading.Thread): def __init__(self,

How does one incorporate a Django application into an existing twisted server?

你说的曾经没有我的故事 提交于 2019-12-06 15:20:46
I'm looking to add/serve a complicated django application, to an existing twisted server (the existing twisted server doesn't serve any http services, at least not on the standard ports, so I can use port 80 for this work). All of the examples I can find to date are for earlier versions of twisted, and do not seem to work, out of the box, with the latest version. Where can I find an up to date tutorial, set of examples or recipe, showing the correct wiring for serving a complex Django application through the latest version of twisted? More specifically, I have gotten close with this little