asyncore question

S

Stéphane Ninin

Hi.

I am trying to understand the asyncore module.

I read it and found something which seems strange
(nb: I am still using Python 2.2.2).

I will keep only what seems useful in this post:

class dispatcher:

# [...]

def __init__ (self, sock=None, map=None):
if sock:
self.set_socket (sock, map)
# I think it should inherit this anyway
self.socket.setblocking (0)
self.connected = 1
# XXX Does the constructor require that the socket passed
# be connected?
try:
self.addr = sock.getpeername()
except socket.error:
# The addr isn't crucial
pass
else:
self.socket = None

def add_channel (self, map=None):
#self.log_info ('adding channel %s' % self)
if map is None:
map=socket_map
map [self._fileno] = self

def create_socket (self, family, type):
self.family_and_type = family, type
self.socket = socket.socket (family, type)
self.socket.setblocking(0)
self._fileno = self.socket.fileno()
self.add_channel()


My problem is the following:
what happens if dispatcher is created with non global map
but with no socket, like:

d=dispatcher(self,sock=None,map=some_map)

then create_socket called:

d.create_socket()

This dispatcher will be added to the global map.
But probably user will call asyncore.loop(map=some_map),
as d was buillt with this map.

Is there not something wrong here, or am I just missing something ?

Regards,
 
R

Richie Hindle

[Stéphane]
what happens if dispatcher is created with non global map
but with no socket, like:

d=dispatcher(self,sock=None,map=some_map)

then create_socket called:

d.create_socket()

This dispatcher will be added to the global map.
But probably user will call asyncore.loop(map=some_map),
as d was buillt with this map.

Is there not something wrong here, or am I just missing something ?

I believe it's an oversight in asyncore. Either create_socket should take
a map parameter, or __init__ should store the initial map and
create_socket should use it. One workaround is to create the socket
yourself and call set_socket(sock, some_map).
 
R

Raymond Hettinger

This dispatcher will be added to the global map.
I believe it's an oversight in asyncore. Either create_socket should take
a map parameter, or __init__ should store the initial map and
create_socket should use it. One workaround is to create the socket
yourself and call set_socket(sock, some_map).

Please submit a bug report.


Raymond Hettinger
 
S

Stéphane Ninin

Also sprach Stéphane Ninin :
Oops, sorry for delay.

Where can I submit it ?

No need to reply... :) I found the page, and it seems a similar bug is
already there, "[ 758241 ] asyncore with non-default map problems".
I guess that I could submit a patch if I find some time.


Thanks & regards,
 
S

Stéphane Ninin

Also sprach Raymond Hettinger :
Please submit a bug report.

I think this patch should work,

*** asyncore.py Mon Sep 29 16:20:13 2003
--- asyncore-new.py Mon Sep 29 16:20:26 2003
***************
*** 201,206 ****
--- 201,211 ----
addr = None

def __init__(self, sock=None, map=None):
+ if (map is None):
+ self.map = socket_map
+ else:
+ self.map=map
+
if sock:
self.set_socket(sock, map)
# I think it should inherit this anyway
***************
*** 248,254 ****
self.socket = socket.socket(family, type)
self.socket.setblocking(0)
self._fileno = self.socket.fileno()
! self.add_channel()

def set_socket(self, sock, map=None):
self.socket = sock
--- 253,259 ----
self.socket = socket.socket(family, type)
self.socket.setblocking(0)
self._fileno = self.socket.fileno()
! self.add_channel(self.map)

def set_socket(self, sock, map=None):
self.socket = sock
***************
*** 353,359 ****
raise socket.error, why

def close(self):
! self.del_channel()
self.socket.close()

# cheap inheritance, used to pass all other attribute
--- 358,364 ----
raise socket.error, why

def close(self):
! self.del_channel(self.map)
self.socket.close()

# cheap inheritance, used to pass all other attribute


should I add it first to the bug [758241],
or create a patch for it ?
In that case, how to connect the patch to the bug it is supposed to solve ?

I guess I am a bit out of topic here, in that case where should I ask
such questions ?


Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top