twisted

Asynchronous WSGI with Twisted

痞子三分冷 提交于 2019-12-09 06:01:03
问题 I'm building a web interface for a twisted application and would like to use WSGI rather than twisted.web directly (since the rest of the website is WSGI and I already have a substantial WSGI codebase). The Twisted documentation page I found about WSGIResource (http://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html) states: Like any other WSGI container, you can't do anything asynchronous in your WSGI applications, even though this is a Twisted WSGI container. Does this have

Python twisted: how to schedule?

你。 提交于 2019-12-09 04:51:41
问题 Having 1-day experience in Twisted I try to schedule message sending in reply to tcp client: import os, sys, time from twisted.internet import protocol, reactor self.scenario = [(1, "Message after 1 sec!"), (4, "This after 4 secs"), (2, "End final after 2 secs")] for timeout, data in self.scenario: reactor.callLater(timeout, self.sendata, data) print "waited %d time, sent %s\n"%(timeout, data) Now it sends messages, but I have 2 problems: 1) "timeout" is going from "now", and I want to count

# Python安装scrapy失败解决方法

大城市里の小女人 提交于 2019-12-08 21:33:08
Python安装scrapy失败解决方法 环境:win10+Python3.6 使用 python -m pip install scrapy 命令安装scrapy显示错误如下: building ‘twisted.test.raiser’ extension error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools 在不想安装VS的背景下,搜索相关资料想解决这个问题 解决方案 首先确定你电脑上安装的python 是32位的还是64位的,我这里安装的是64位的 然后到 http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted 下载twisted对应版本的whl文件 我下载的版本是Twisted‑17.9.0‑cp36‑cp36m‑win_amd64.whl( cp后面是python版本,amd64代表64位 ),32位的应该去下载32位对应的文件 下载好后,执行如下命令: python -m pip install E:\Twisted-17.9.0-cp36-cp36m-win_amd64

the sample python twisted event driven web application increments request count by 2, why?

♀尐吖头ヾ 提交于 2019-12-08 20:39:42
问题 The sample code for a basic web server given by http://twistedmatrix.com/trac/ seems to increment the request counter by two for each request, rather than by 1. The code: from twisted.web import server, resource from twisted.internet import reactor class HelloResource(resource.Resource): isLeaf = True numberRequests = 0 def render_GET(self, request): self.numberRequests += 1 request.setHeader("content-type", "text/plain") return "I am request #" + str(self.numberRequests) + "\n" reactor

Twisted: why is it that passing a deferred callback to a deferred thread makes the thread blocking all of a sudden?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 18:01:01
问题 I unsuccessfully tried using txredis (the non blocking twisted api for redis) for a persisting message queue I'm trying to set up with a scrapy project I am working on. I found that although the client was not blocking, it became much slower than it could have been because what should have been one event in the reactor loop was split up into thousands of steps. So instead, I tried making use of redis-py (the regular blocking twisted api) and wrapping the call in a deferred thread. It works

Fetching Email in Twisted using IMAP

二次信任 提交于 2019-12-08 13:16:54
问题 I am trying to fetch emails on a gmail account using twisted, and to say the least it has been a pain, looking at email is their a clear explanation and structure (it seems hacked together at best). I am trying to grab attachments yet the attachment isn't any where in sight. I am using the example IMAP Client from twisted and modified it, I am using fetchAll('1: ') to get the email and then getting the first email but I can't find the email attachment that is on that email (I checked it is

Getting email message after IMAP IDLE command exists response

自作多情 提交于 2019-12-08 10:04:59
问题 Is it safe to use the total number of messages in the exists response as a way to then get the uid? 7.3.1. EXISTS Response Contents: none The EXISTS response reports the number of messages in the mailbox. This response occurs as a result of a SELECT or EXAMINE command, and if the size of the mailbox changes (e.g., new messages). The update from the EXISTS response MUST be recorded by the client. Example: S: * 23 EXISTS In app output 2013-02-02 01:24:42-0500 [IMAP4Client (TLSMemoryBIOProtocol)

How to asynchronously read data via modbus/TCP and send them to web

做~自己de王妃 提交于 2019-12-08 09:46:22
问题 I need to receive data from device connected via Ethernet (modbus/TCP) and send it to webpage (maybe using web sockets). I can't find good examples. Now I can connect with driver and print values using ModbusClientProtocol.read_input_registers() but I had to create own factory and protocol class. I am using autobahn, twisted, pymodbus. 回答1: I've no familiarity with modbus or pymodbus, so I'm guessing and leaving a lot of blanks for you to fill in. This is hacked out of something I recently

How to handle connection or download error in Scrapy?

风流意气都作罢 提交于 2019-12-08 08:09:48
问题 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):

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

蹲街弑〆低调 提交于 2019-12-08 06:45:57
问题 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