twisted

stop a twisted reactor after a gatherResults has finished

你。 提交于 2019-12-08 05:53:53
问题 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

Python, Call a class function from another class

旧巷老猫 提交于 2019-12-08 04:55:26
问题 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

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

孤街醉人 提交于 2019-12-08 04:50:21
问题 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

Cleanup of resources with the SMTP module of Twisted Python

核能气质少年 提交于 2019-12-08 02:51:48
问题 This is related to the previously answered question here: Logging SMTP connections with Twisted. I have a database resource that I create in each instance of ConsoleMessageDelivery that I need to ensure is cleaned up when the socket is closed. I have a WrappingFactory called DenyFactory and the DenyFactory.unregisterProtocol method is called when the socket is closed, but I have no way (that I can figure out) how to access the resource created in the ConsoleMessageDelivery instance that's

Override Autobahn/Twisted WebsocketClientProtocol class

試著忘記壹切 提交于 2019-12-08 02:43:42
问题 I want to override my WebSocketClientFactory class to allow a job queue to be filled by the incoming data. Here's the connection code I am trying factory = WebSocketClientFactory("ws://localhost:7096") job_queue = Queue.Queue() factory.protocol = BridgeSocket(job_queue) connectWS(factory) And here's my socket class: class BridgeSocket(WebSocketClientProtocol): def __init__(self,producer_queue): self.producer_queue = producer_queue def sendHello(self): self.sendMessage("hello") def onOpen(self

Python + Twisted + sqlanydb = abort()

别来无恙 提交于 2019-12-08 02:09:49
问题 I'm using Twisted 11 together with SQLAnywhere 12 via the official sqlanydb driver. Generally, it works fine. But occasionally the application crashes with an abort on the first query. If one query worked, all following work too. However my tests run only seldom through. That's awful to develop with and strace doesn't tell me anything informative too. Sometimes it crashes inside of select(), sometimes in mmap()... I'm running 64bit Linux and run locally the Sybase as dbeng12 for testing. Is

How to set logging level in twisted?

…衆ロ難τιáo~ 提交于 2019-12-08 01:26:50
问题 I am using autobahn package with twisted which shows debug message for me every connect to websocket. I tried to switch logging level to info but had no success: import logging logging.basicConfig(level=logging.INFO) Is there an easy way to switch log level? Updated. Here is the twisted_service.py: from twisted.application import service from twisted.logger import Logger import logging logging.basicConfig(level=logging.INFO) class WebsocketService(service.Service): log = Logger() def

twisted location header redirect

笑着哭i 提交于 2019-12-07 21:30:50
问题 From the render_GET method of a Resource in twisted , is it possible to redirect to a different url entirely (hosted elsewhere) request.redirect(url) doesn't appear to do anything, and neither does twisted.web.util.Redirect The equivalent in php would be, header('location:'.$url); EDIT this is the code I'm running from twisted.web import server, resource from twisted.internet import reactor class Simple(resource.Resource): isLeaf = True def render_GET(self, request): request.redirect("www

(转) Twisted :第十七部分 构造"回调"的另一种方法

懵懂的女人 提交于 2019-12-07 19:43:32
简介 这部分我们将回到"回调"这个主题.我们将介绍另外一种写回调函数的方法,即在Twisted中使用 generators . 我们将演示如何使用这种方法并且与使用"纯" Deferreds 进行对比. 最后, 我们将使用这种技术重写诗歌客户端. 但首先我们来回顾一下 generators 的工作原理,以便弄清楚它为何是创建回调的候选方法. 简要回顾生成器 你可能知道, 一个Python生成器是一个"可重启的函数",它是在函数体中用 yield 语句创建的. 这样做可以使这个函数变成一个"生成器函数",它返回一个" iterator "可以用来以一系列步骤运行这个函数. 每个迭代循环都会重启这个函数,继续执行到下一个 yield 语句. 生成器(和迭代器)通常被用来代表以惰性方式创建的值序列. 看一下以下文件中的代码 inline-callbacks/gen-1.py : def my_generator(): print 'starting up' yield 1 print "workin'" yield 2 print "still workin'" yield 3 print 'done' for n in my_generator(): print n 这里我们用生成器创建了1,2,3序列. 如果你运行这些代码,会看到在生成器上做迭代时,生成器中的 print

Using PythonAnywhere as a game server

徘徊边缘 提交于 2019-12-07 16:33:03
问题 I'm building a turn-based game and I'm hoping to implement client-server style networking. I really just need to send the position of a couple of objects and some other easily encodable data. I'm pretty new to networking, although I've coded some basic stuff in socket and twisted. Now, though, I need to be able to send the data to a computer that isn't on my local network, and I can't do port forwarding since I don't have admin access to the router and I'm also not totally sure that would do