FAQ Database Discussion Community


Can't figure out TypeError: __init__() takes exactly 3 arguments (2 given)

python,twisted,kivy
I am working on a multi clients/ server chat app that can write input from one client to multi clients. For the client side it's working well, yet for the server side I want to add a part where it can print out the input from the clients on its...

Python Twisted: What Is Received with DataReceived and What Should I Probably Use Instead

python,twisted
I'm tooling around with a text-based adventure game in Python with Twisted and I think I've fundamentally misunderstood what comes back with Twisted's dataReceived function. I've got the following as part of my overall code; def process(self, data): print "Got command {}, {}".format(data, len(data)) if data == "test": print "DEBUG:...

Running Twisted on Azure Websites

twisted,azure-web-sites,twisted.web
Can Azure Websites host Twisted applications? e.g. something like: from twisted.internet import reactor from twisted.web import server site = server.Site(myresource) reactor.listenTCP(80, site) reactor.run() From http://azure.microsoft.com/en-us/documentation/articles/web-sites-python-configure/ it sounds like only WSGI apps are supported, but just wanted to confirm from an Azure Websites expert that there's no way to directly run...

Lag in receiving messages from Twisted server

python,twisted,lag
I have a very simple client and server (both written in Python using Twisted). The server loops and sends a message out to the client every X millis. The server is running on my Raspberry Pi and my client is on my laptop, both of which are connected to my...

How do I pipe stdout of cmd1 to stdin of cmd2 in twisted where cmd1 process is on a twisted client and cmd2 is a process on a server?

python,linux,process,pipe,twisted
How do i connect the stdout of a spawnProcess to the stdin of another spawnProcess in twisted, where spawnProcess with the stdout is on the client and the stdin spawnprocess on the server? The CLI command in bash is btrfs send @mysubvol | btrfs receive /some/path/. With rfd, wrd =...

twisted Int16StringReceiver little endian byte order

python,python-2.7,byte,twisted
I'm trying to use this class provided by twisted to frame my tcp stream. But the default format they have is in big endian byte order but I need to read in little endian. So I did: class Player(basic.Int16StringReceiver): structFormat = "<H" def stringReceived(self, packet): print ':'.join(x.encode('hex') for x in...

Terminate previous autobahn websocket call when a new message arrives

python,websocket,twisted,autobahn
I am designing a feature that gives autocomplete-like search results through a websocket. When the user types fast enough, often their previous query becomes outdated because they are already asking for new information. Is there any way to recognize when a new query is incoming, and terminate a previous query?...

How to deal with multiple serial ports for R/W using twisted?

python,serial-port,twisted
Going through the twisted finger tutorial and seen the SO questions: Question-1 Question-2 However, I can't (yet) write a twisted program that can read & write from multiple serial ports, especially where the protocol involves reading single or multiple lines, and writing back to the device accordingly. What I am...

Use RFC2217 network serial ports with Twisted Python?

python,twisted,pyserial,rfc2217
Is there a way to connect to an RFC2217 networked serial port with Twisted Python? Pyserial seems to support it via the serial.serial_for_url("rfc2217://...") function. And they indicate that twisted uses pyserial for managing serial connections, however twisted.internet.serialport.SerialPort seems to expect a port name or number which suggests it is just...

Having trouble with a simple Twisted chat server

python,client,chat,twisted,server
When I try and run this (see code below) I get the "connection made" response from the server and the command prompt to write an input. However when I try and enter the input it just hangs and the server doesn't seem to receive the message. Anyone know why this...

Twisted SSL socket connection slowdown

python,sockets,ssl,twisted
How do I scale my Twisted server to handle tens of thousands of concurrent SSL socket connections? The first few hundred clients are connected relatively quickly, but as the count approaches 3000, it begins to crawl at about 2 connections made per second. I am load testing using the loop...

Twisted RPC message aggregation

python,twisted,rpc
I'm working with a python application that makes remote procedure calls, using Twisted Perspective broker's callRemote, on a TCP connection. From a system call trace, it appears that multiple remote procedure calls from the sender could be aggregated together into a single sendto() call on the socket. The same behavior...

Writing more than just “hello”

python,twisted
If my understanding is correct, this example in the docs could only write "hello" once: from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor class Helloer(DatagramProtocol): def startProtocol(self): host = "192.168.1.1" port = 1234 self.transport.connect(host, port) print "now we can only send to host %s port %d" % (host, port) self.transport.write("hello")...

Twisted and Tkinter Issue with Tk Text widget

python,tkinter,twisted
I am building a simple tkinter gui for the twisted application (server side). The code below works well except when I want to write the data send from twisted(dataReceived method), it deletes all the previous messages inside Text widget and writes at the first line. I want to write the...

python twisted multithreaded tcp proxy

python,twisted
I am trying to write a TCP proxy using python's twisted framework. I started with the twisted's port forward example and it seems to do the job in a standard secnario. The problem is that I have a rather peculiar scenario. What we need to so is to process each...

Python Twister Reactor callLater time source?

python,twisted,reactor
I figured out that when I schedule a function with : reactor.callLater(delay, function) If during the delay, the system date is changed, the delay set in reactor.callLater will not be respected. So, for example, if at 15:00:00 I schedule my function in 30 secondes : reactor.callLater(30, function) If during these...

logging to file with twistd and python logging

python,ubuntu,logging,twisted
When I run my twisted application like this: twistd --pidfile ./twistd.pid -l $HOME/logs/my_application.log -oy service.tac I find that it does not log anything sent through the python logging system. I noticed that there is a "PythonLoggingObserver" in twisted, but that redirects twisted logs to the logging module. I would like...

After connecting to a server, wait for user input without blocking the main reactor and send it to the server

python,twisted,stdio
I'm having a bit of trouble with Python and Twisted. I've started writing a a client that connects to a server and sends messages to it (which the server, for the moment, just echoes back). This is all well and good, but I need a way for my program to...

Python Twisted: read from file and send as TCP server

python,network-programming,twisted
I am completely new to Twisted, but it looks very promising for my project. I would like to write a Python Twisted application which reads a record from text file every x seconds and contemporary listen on a TCP port (acting as TCP server). If no clients are connected to...

Twistd executable on Python3

python,python-3.x,twisted
I have a Twisted daemon application that works without raising any problem on Python 2 using twistd. However, I want to support Python3 as well, and although all my code works, it seems that the twistd executable is not present on the Twisted version for python 3 (apparently the twisted.scripts...

Data not received by twisted socket connection

python,sockets,twisted
I have a twisted server script listening on a unix socket and it receives the data when the client is in twisted but it doesn't work if i send it via a vanilla python socket code. class SendProtocol(LineReceiver): """ This works """ def connectionMade(self): print 'sending log' self.sendLine(self.factory.logMessage) if __name__...

Python Twisted client not able to receive response from server

python,networking,twisted
I have a client written using python-twisted (http://pastebin.com/X7UYYLWJ) which sends a UDP packet to a UDP Server written in C using libuv. When the client sends a packet to the server, it is successfully received by the server and it sends a response back to the python client. But the...

What does this python autobahn code need to use the keyword yield?

python,python-2.7,twisted,autobahn
Why does this python autobahn example code uses yield sleep(1) and not simplysleep(1) ? class Component(ApplicationSession): """ An application component that publishes an event every second. """ @inlineCallbacks def onJoin(self, details): print("session attached") counter = 0 while True: print(".") self.publish('com.myapp.topic1', counter) counter += 1 yield sleep(1) if __name__ == '__main__':...

Installing Twisted through pip broken on one server

python,pip,virtualenv,twisted
I am setting up a virtualenv on a new server, and when I used pip on our requirements file, it kept dying on Twisted. I commented the Twisted line out, and everything else installed fine. At the command line, this is the output I see when I try to install...

Set a timeout for an UDP socket with Twisted (python)

python,sockets,twisted
I'm using Twisted in a python program. I send data every minute and receive data on a UDP socket and I need to set a timeout. I found a way to do this, but I would like to know if it's a good way to do that. This is the...

Python Twisted - How to set log levels for twisted.logger

python,logging,twisted
Twisted recently came out with a new logging module: twisted.logger. I've read through the documentation[1], but I haven't been able to find where one sets the actual log level. The section on log observers[2] suggests that you might configure a predicate to do this if you are explicitly configuring your...

Django: communicate with TCP server (with twisted?)

python,django,tcp,twisted
I have a django application, that needs to talk to a remote TCP server. This server will send packages and depending on what the package is, I need add entries to the database and inform other parts of the application. I also need to actively send requests to the TCP...

Unable to add item to GtkListBox outside of my Gtk.Window

python,twisted,gtk3,pygobject
I'm attempting to make a small GTK 3 irc client in Python 2.7 with twisted. Currently, I have a very basic client that can successfully connect to an irc network and display some stuff in the main text area. I'm currently trying to work on implementing multiple channel support, however...

Twisted transport.write in seperate thread

python,multithreading,twisted
I want to receive the message from clients and send message to them through a separate independent process. The code I tried with uses the twisted method of threading. I tried to run the method sendMessage on a different thread to keep on receiving the message from client but it...

Twisted simulate timer with callback

python,callback,twisted
I am new to twisted and i wanted to simulate a timer or something of the sort. What i have is: def whatToCall(): print 'Before: ' + str(len(globals.session_manager)) for ses in globals.session_manager: if ses.expired is True: globals.session_manager[ses.id] = None print 'After: ' + str(len(globals.session_manager)) reactor.callLater(15, whatToCall(), None) def callBacks(): reactor.callLater(15,...

twisted python - sending message via GPIO that isn't received until the enter key is pressed

python,multithreading,raspberry-pi,twisted,gpio
i have a occurrence with twisted python that i can't get resolved. GPIO.add_event_detect(24, GPIO.RISING, callback=pDetected, bouncetime=1000) def pDetected(channel): communicator.sendNotifications(factory) class notification(Protocol): def connectionMade(self): print "connection made but not added" def connectionLost(self, reason): self.factory.clients.remove(self) def dataReceived(self, data): lineMessage = data.split('|') theCommand = lineMessage[0] theContent = lineMessage[1] if theCommand == "welcome": self.name...

Twisted getPage, exceptions.OSError: [Errno 24] Too many open files

python-2.7,twisted
I'm trying to run the following script with about 3000 items. The script takes the link provided by self.book and returns the result using getPage. It loops through each item in self.book until there are no more items in the dictionary. Here's the script: from twisted.internet import reactor from twisted.web.client...

Python - access class method (using twisted)

python,twisted
I'm working with this example of an iPhone Chart Server and all is working as expected. What I wanted to ask is if and how I can use message(self, message) outside the IphoneChat class... For example if I have an event triggering every hour I want to be able to...

How do I import modules when using Twisted subprocesses and virtualenvwrapper?

python,twisted,virtualenv,virtualenvwrapper
I am trying to write a web server in Twisted which takes a user input and draws an image depending on the input. For the server, I have a simple Twisted web server. In order to process the image drawing, I am using python wand. I am working in a...

Debugging twisted application using PyCharm

python,debugging,twisted,pycharm
I am fighting a few hours trying to configure PyCharm for debugging my app. I was looking for solution, but twisted seems to not be so popular and there is weak support. Below I put error log that i got. /usr/local/bin/python3.4m -u /Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_run_in_console.py 57276 57277 /usr/bin/twistd -y /Users/artur/projs/private/elanga-web/start_app.tac Running...

how install jsonrpc on macos for python27

python,twisted
I want to check the operation of the code: from txjsonrpc.web import jsonrpc from twisted.web import server from twisted.internet import reactor class Math(jsonrpc.JSONRPC): """ An example object to be published. """ def jsonrpc_add(self, a, b): """ Return sum of arguments. """ return a + b reactor.listenTCP(7080, server.Site(Math())) reactor.run() but I...

Twisted callback loop blocking further data from being recieved

python,callback,twisted,deferred
When a callback loop is running in Twisted, it was my impression that the reactor was still able to send/receive data from the server, as it was able to function 'between' the callbacks. However, when I run the script below, it entirely ignores the self.transport.write() line. The server is just...

Calling Python code from Twisted

python,multithreading,twisted
First of all, I should say that this might more a design question rather than about code itself. I have a network with one Server and multiple Clients (written in Twisted cause I need these asynchronous non-blocking features), such server-client couple it's just only receiving-sending messages. However, at some point,...

Twisted Python - In deferred's callback's function call, raised exception not displayed in stdout

python,exception,twisted
Test Setup I have an asynchronous Twisted HTTP server for handling POST: class HttpResource(Resource): isLeaf = True; def render_POST(self, request): ... if __name__ == "__main__": factory = Site(HttpResource()) reactor.listenTCP(8000, factory) reactor.run() I created a simple test() function that raises an exception: def test(): print "test() called" raise Exception("Exception raised!") Capturing...

Integrating HID access with evdev on linux with Python twisted

python,linux,twisted,evdev
On a linux machine (Debian wheezy) I am trying to write an event-based server that does the following: Grab exclusive input to the input device (a special keyboard) to prevent the keystroke get into the usual event chain. Register for events in the twisted reactor Register callback at the deferred...

Reading file to stdout with twisted

python,asynchronous,twisted
How do we read a file (non-blocking) and print it to the standard output (still non-blocking)? This is the esiest way I can think of but it leaves you with a feeling there must be a better way. Something exposing some LineReceiver - like line by line modification - functionality...

In the context of a buildbot master.cfg file, how do I instantiate a class based on a string using native modules

python,twisted,introspection,buildbot
In stock python, I can do the following to instantiate a class based on a string containing its name: #!/usr/bin/env python2.7 import sys class Foo(object): pass cls = getattr(sys.modules[__name__], 'Foo') instance = cls() print repr(instance) Which outputs the following: [email protected]›~⁑ ./test.py <__main__.Foo object at 0x1095b0a10> I'd like to do something...

twisted - is Factory object thread safe?

python,multithreading,twisted
Following code listen on 2 port, when there is message modify a global dict object. And there is a timer will modify dict also. d = {} class x(Protocol): def dataReceived(self, data): # according to data call x's function self.f() def f(self): global d d['x'] = 'x' class y(Protocol): def...

Python twisted, reactor.callLater() not defering

twisted
The following code snippet is from a python poker server. The program works except when trying to delay the start of a tourney when a reactor.callLater is used. The variable "wait" gets its integer from an xml file which has a setting of "60". However the delay is never implemented...

How to advance clock and going through all the events

python,twisted,trial
Reading this answer (point 2) to a question related to Twisted's task.Clock for testing purposes, I found very weird that there is no way to advance the clock from t0 to t1 while catching all the callLater calls within t0 and t1. Of course, you could solve this problem by...

HTTPS request in twisted that checks the certificate

python,ssl,https,twisted,twisted.web
In my twisted app I want to make an asynchronous request to Akismet to check for spam. Akismet reasonably uses HTTPS, so I've been following the web client guide on SSL in the docs. But there's this part that worries me: Here’s an example which shows how to use Agent...

Twisted SSE server subscribed to Redis via pubsub

python,redis,twisted,server-sent-events
I'm trying to build a server in Twisted which would let clients connect using Server Sent Events. I would like this server also to listen to Redis and if a message comes then push it to the connected SSE clients. I have the SSE server working. I know how to...

How to Log to a variable or write observer that sends messages to variable in Twisted / Autobahn

python,logging,twisted,observers,autobahn
I am writing a websocket client that will receive updates every few seconds or so utilizing autobahn with twisted. I am successfully logging the data using multiple observers, however I want to use part of the messages I am receiving to send to a dataframe (and eventually plot in real...

Flushing Twisted's write buffer

python,tcp,buffer,twisted
Twisted's Connection class inherits the write method from the abstract class FileDescriptor. As you can see here, the class has a buffer which is not flushed until the total number of buffered bytes is greater than bufferSize (attribute in class FileDescriptor). For my specific needs, I'd like to write data...

Use TLS and Python for authentication

python,authentication,ssl,twisted
I want to make a little update script for a software that runs on a Raspberry Pi and works like a local server. That should connect to a master server in the web to get software updates and also to verify the license of the software. For that I set...

'NoneType' object has no attribute '_app_data' in scrapy\twisted\openssl

python,openssl,scrapy,twisted,pyopenssl
During the scraping process using scrapy one error appears in my logs from time to time. It doesnt seem to be anywhere in my code, and looks like it something inside twisted\openssl. Any ideas what caused this and how to get rid of it? Stacktrace here: [Launcher,27487/stderr] Error during info_callback...

Can somebody explain what this piece of twisted does?

python,linux,python-2.7,twisted,http-proxy
class ConnectProxy(Proxy): requestFactory = ConnectProxyRequest connectedRemote = None def requestDone(self, request): if request.method == 'CONNECT' and self.connectedRemote is not None: self.connectedRemote.connectedClient = self else: Proxy.requestDone(self, request) What does self.connectedRemote.connectedClient = self do ?...

How to limit the number of simultaneous connections in Twisted

python,python-2.7,asynchronous,twisted,twisted.internet
so I have a twisted server I built, and I was wondering what is the best way to limit the number of simultaneous connections? Is having my Factory return None the best way? When I do this, I throw a lot of exceptions like: exceptions.AttributeError: 'NoneType' object has no attribute...

CPU usage at the time of starting twisted reactor

python,python-2.7,twisted,twisted.internet
I am monitoring CPU usage of python script which contains following code from twisted.internet import reactor, task def fun(): print "I don't know why CPU usage increases in the beginning" lc = task.LoopingCall(fun) lc.start(10) reactor.run() I am using ps command to get CPU usage(in percentage) ps aux|grep <script_name>|grep -v grep|awk...

ImportError in running django from twisted

python,django,twisted,python-import
I'm trying to run a Twisted program, which serves some requests and also runs a Django app through WSGI, and routes some requests to it. Folder structure is something like this: code |-- __init__.py |-- main.py |-- django_proj | |-- __init__.py | |-- manage.py | |-- django_proj | | |--...