twisted

Triggering events in twisted from another thread

廉价感情. 提交于 2019-12-10 19:05:06
问题 I have an application which, for convenience (I am reusing existing code) has been split into two different threads: one thread running the twisted reactor another thread running an interactive menu One of the things I want to perform from the interactive menu is to interact with the reactor. Once the user gives a specific command, I want to trigger a twisted event. Here is a very simplified version of my code: from twisted.spread import pb from twisted.internet import reactor import

Running more than one spider in a for loop

余生颓废 提交于 2019-12-10 17:37:17
问题 I try to instantiate multiple spiders. The first one works fine, but the second one gives me an error: ReactorNotRestartable. feeds = { 'nasa': { 'name': 'nasa', 'url': 'https://www.nasa.gov/rss/dyn/breaking_news.rss', 'start_urls': ['https://www.nasa.gov/rss/dyn/breaking_news.rss'] }, 'xkcd': { 'name': 'xkcd', 'url': 'http://xkcd.com/rss.xml', 'start_urls': ['http://xkcd.com/rss.xml'] } } With the items above, I try to run two spiders in a loop, like this: from scrapy.crawler import

Scrapy error:User timeout caused connection failure

扶醉桌前 提交于 2019-12-10 17:35:42
问题 I'm using scrapy to scrape the adidas site: http://www.adidas.com/us/men-shoes . But it always shows error: User timeout caused connection failure: Getting http://www.adidas.com/us/men-shoes took longer than 180.0 seconds.. It retries for 5 times and then fails completely. I can access the url on chrome but it's not working on scrapy. I've tried using custom user agents and emulating header requests but It's still doesn't work. Below is my code: import scrapy class AdidasSpider(scrapy.Spider)

Twisted multiple protocols

久未见 提交于 2019-12-10 17:27:47
问题 I am looking to learn twisted for a project I am working on. The project would require the server to respond to HTTP requests as well as other protocols over a TCP connection. Is twisted capable of handling multiple protocols at the same time? I want to use Twisted Web to help with the HTTP, but at the same time need to respond to TCP connections over other ports. 回答1: Definitely, yes. Twisted is a really good choice for this kind of needs, when multiple protocols need to work together. Look

Installing Twisted for Python using pip: error: Microsoft Visual Studio failed with exit status 2

北慕城南 提交于 2019-12-10 17:20:29
问题 When I try to install the python package Twisted on my windows 10 machine running python3.7, I'm unable to build a Wheel from the .tarz file and I eventually get the following output: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DWIN32=1 -Ic:\users\dario\appdata\local\programs\python\python37-32\include -Ic:\users\dario\appdata\local\programs\python\python37-32\include "-IC:\Program Files

What is the correct way to close a Twisted conch SSH connection?

送分小仙女□ 提交于 2019-12-10 14:52:26
问题 What is the correct way to close a Twisted conch SSH connection? Is there an explicit way to do this? All of the Twisted conch examples I have seen close the SSH channel then stop the reactor. The reactor shutdown seems to handle closing the connection. However, I'm using the wxreactor with wxPython and I do not want to stop the reactor, but I want to close the ssh connection when I'm finished with it. After looking at t.c.s.connection it seemed like the serviceStopped() method was the way to

Subclassing static.File

邮差的信 提交于 2019-12-10 14:49:25
问题 I'm new to Twisted and I'm having trouble with some necessary subclassing for the static.File in twisted. i'm trying to set request headers within the subclass. class ResponseFile(static.File): def render_GET(self, request): request.setHeader('Content-Disposition', ['attachment ; filename="tick_db_export.csv"']) static.File.render_GET(self, request) if __name__ == "__main__": from twisted.internet import reactor root = ResponseFile('WebFolder') testHandler = TestHandler() root.putChild('main'

how do twisted/tornado et cetera work

被刻印的时光 ゝ 提交于 2019-12-10 13:57:14
问题 I understand that they work in some way distinct from making a thread per user. How exactly does that work? (Does 'non-blocking' have something to do with it?) 回答1: From the Twisted documentation: The reactor is the core of the event loop within Twisted -- the loop which drives applications using Twisted. The event loop is a programming construct that waits for and dispatches events or messages in a program. It works by calling some internal or external "event provider", which generally

How do I interact with a child process pretending to be a terminal?

安稳与你 提交于 2019-12-10 13:47:38
问题 I'm trying to interact with an NCURSES program. As an example I'm using GNU Screen and run aptitude inside. (you could try it with mc instead.) The program below starts a screen session with -x to connect to my session. I want to navigate by pressing Arrow-down and Arrow-up. If I send 'q' for quit I see a box pop up in my other screen session. What do I need to do to get special keys like arrow keys working? It currently seems to ignore the VT102 sequence I'm sending. from twisted.internet

Keyboard input using stdio.StandardIO in twisted python

扶醉桌前 提交于 2019-12-10 13:26:17
问题 I have a doubt in twisted python related to my multiclient chat server program. that is, when we give input from keyboard using stdio.StandardIO, where it is stored when we run the reactor? Can anybody give me the answer, please.. 回答1: twisted.internet.stdio.StandardIO doesn't "store" data anywhere. It is a transport which you associate with a protocol. The protocol you associate with it can do anything you want with the data delivered to it. You can find two examples of using StandardIO in