473,660 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is asynchat broken or just not intended to work like other dispatchers? [PATCH]

Simple asyncore application where I wanted to use an explicit map (1)
rather than the automagic default. Worked fine until I tried to use
asynchat to handle an interactive status and control connection (3) and
found it had no notion about using a non-default map. After convincing
myself that this must be a simple oversight in asynchat, I applied the
following patch to a local copy. Of course now I have to carry around
this hacked-up version of asynchat, which sort of defeats the
"batteries included" simplicity thing. :-(

Anyway, in hopes that maybe in a few years I can lose that ugly
duplication, I offer this patch for what I assume was an oversight:

--- my_chat.py (revision 6)
+++ my_chat.py (working copy)
@@ -59,11 +59,11 @@
ac_in_buffer_si ze = 4096
ac_out_buffer_s ize = 4096

- def __init__ (self, conn=None):
+ def __init__ (self, conn=None, map=None):
self.ac_in_buff er = ''
self.ac_out_buf fer = ''
self.producer_f ifo = fifo()
- asyncore.dispat cher.__init__ (self, conn)
+ asyncore.dispat cher.__init__ (self, conn, map)

def collect_incomin g_data(self, data):
raise NotImplementedE rror, "must be implemented in subclass"

(rev 6 was the checkin of the stock asynchat.py under a different name,
of course)

For the docs I cannot make a specific suggestion: it depends on what is
intended to be exposed and what would be better ignored outside the
implementation. It's at moments like this that I miss the explicit
declaration of things as public/protected/private from C++ a little.
Sure, it's rather officious, but it has value in reflecting some
important design criteria in the code... it's better than nothing.
(1) maybe I guessed wrong on this score about what was the yuckier
un-or-incompletely-documented bit to use, but non-default maps are at
least mentioned in asyncore's docs, and when you dig into the code (2)
to see what's going on that's not documented (4) it's obvious that at
least the dispatchers defined in asyncore.py are careful to allow for
the optional map argument, so I think it was reasonable to prefer to
use my own mapping with this interface rather than reaching in and
frobbing asyncore's socket_map... especially after puzzling over the
mysterious way it's defined (maybe?) in asyncore.

(2) code is NOT documentation, dammit. Well, it's not *good*
documentation, and everyone knows it, as Python's docstrings and XP's
"no written docs, but we have to talk and talk about what's not written
down" (aren't oral traditions grand? not to mention fragile...) stand
in proof of, just to cite a couple obvious examples.

(3) actually it was the other way around: I had that working just fine
using the default mapping, and it was when I moved from the "playing
around to see if asyn* is suitable" to something a little more useful
that I ran into the problem. Whatever.

(4) del_channel was another gem - that seems to be the clean way for a
channel to shut itself down from within its input handling code, as for
example that simple interactive status and control thing when it gets
the "quit" command. Not so much as a hint of it in the docs. I hope
that's not because using it is in fact a bad idea - I had to guess from
looking at the code, so I can't know what the design intent was. :-(

--
I personally refuse to use inferior tools because of ideology. In
fact, I will go as far as saying that making excuses for bad tools
due to ideology is _stupid_, and people who do that think with
their gonads, not their brains. -- Linus
Apr 11 '07 #1
1 1245
En Wed, 11 Apr 2007 11:29:28 -0300, Martin Maney <ma***@two14.ne t>
escribió:
Simple asyncore application where I wanted to use an explicit map (1)
rather than the automagic default. Worked fine until I tried to use
asynchat to handle an interactive status and control connection (3) and
found it had no notion about using a non-default map. After convincing
myself that this must be a simple oversight in asynchat, I applied the
following patch to a local copy. Of course now I have to carry around
this hacked-up version of asynchat, which sort of defeats the
"batteries included" simplicity thing. :-(
This is not a good place for reporting bugs - use
http://sourceforge.net/bugs/?group_id=5470

--
Gabriel Genellina
Apr 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2696
by: Michael Welsh | last post by:
In order to learn sockets in Python I am trying to write a simple group chat server and client. I need a little nudge, please. My question contains some GUI but only as decoration. The root question is asyncore / asynchat. I have read that twisted makes this all simple, but, I wanted to get my hands dirty here for educational purposes. I've managed to build a small echo server with asyncore and asynchat that can handle any number of...
4
3010
by: Joshua Moore-Oliva | last post by:
Ok.. so here is my situation. I have an application that I would love to be able to use asynchat with for it's handle_close, found_terminator etc abstraction on. However, I must use a separate thread for each connection as the work resulting from the communication can result in blocking for an indefinate period of time. What I would love to do for each thread that is created, is to spin off an asynchat subclass and manually run some...
16
3260
by: Rob Snyder | last post by:
Greetings - I've embarked on a small learning project, trying to get a better grasp of the asyncore and asynchat modules. The project involves building a simple instant messenger application for use on our LAN - nothing heavy duty, as 99% of my reason for doing this is just to learn. I got my server portion working well, and I think I understand the basics. Where I'm getting stuck is on the client side, where I'm trying to involve...
10
2202
by: Larry Hastings | last post by:
I'm an indie shareware Windows game developer. In indie shareware game development, download size is terribly important; conventional wisdom holds that--even today--your download should be 5MB or less. I'd like to use Python in my games. However, python24.dll is 1.86MB, and zips down to 877k. I can't afford to devote 1/6 of my download to just the scripting interpreter; I've got music, and textures, and my own crappy code to ship. ...
8
2592
by: Andreas R. | last post by:
Hi again, I'm using Python's asynchat module for networking. When calling the sendall() method of asynchat, I sometimes get the error message "the operation could not complete without blocking". So how do I enable blocking with synchat, or otherwise fix this error? Thanks for the help I've received with asynchat so far in this news group.
15
2037
by: Martin Maney | last post by:
To quote from zipfile.py (2.4 library): # Search the last END_BLOCK bytes of the file for the record signature. # The comment is appended to the ZIP file and has a 16 bit length. # So the comment may be up to 64K long. We limit the search for the # signature to a few Kbytes at the end of the file for efficiency. # also, the signature must not appear in the comment. END_BLOCK = min(filesize, 1024 * 4) So the author knows that there's...
5
2457
by: ludvig.ericson | last post by:
Hello, My question concerns asynchat in particular. With the following half- pseudo code in mind: class Example(asynchat.async_chat): def readable(self): if foo: self.push_with_producer(ProducerA()) return asynchat.async_chat.readable(self)
1
124
by: Jean-Paul Calderone | last post by:
On Tue, 13 May 2008 16:44:11 -0700 (PDT), Giampaolo Rodola' <gnewsg@gmail.comwrote: Why? Isn't this why subtraction exists? If there is a call scheduled to happen at T1 and the current time is T2, then I know that after (T1 - T2) elapses, it will be time to run the call. Why do I have to do any checks at all? I just tell select() to wait that long. Presumably this is just what someone will do if they want to use asyncore with timed...
0
1132
by: davy zhang | last post by:
Python3.0rc1 windowsxp in the lib\asynchat.py def handle_write (self): self.initiate_send() def push (self, data): sabs = self.ac_out_buffer_size if len(data) sabs:
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.