Python 3.3 update

mahalin
2013-04-06
2013-04-09
  • mahalin

    mahalin - 2013-04-06

    Hi. Asyncoro needs updating for Python 3.3.

     
  • Giridhar Pemmasani

    Can you give more details about the problem? Have you tried asyncoro3.py (asyncoro.py is meant for Python-2.7+ whereas asyncoro3.py is meant for Python-3.1+)?

     
  • mahalin

    mahalin - 2013-04-06

    Thanks for the quick response. I think the update is mostly trivial. I've been using it to create a server in Blender. I've been using asyncoro3.

    Running udp.py:

    2013-04-06 15:29:14,599 - asyncoro - uncaught exception in client_proc:
    Traceback (most recent call last):
    File "/home/archie/Seteeri/server/asyncoro-1.3/examples/asyncoro.py", line 3212, in _schedule
    retval = coro._generator.throw(exc)
    File "udp.py", line 18, in client_proc
    yield sock.sendto(msg, (host, port))
    File "/home/archie/Seteeri/server/asyncoro-1.3/examples/asyncoro.py", line 444, in _sendto
    sent = self._rsock.sendto(
    args)
    TypeError: 'str' does not support the buffer interface

    In the udp.py example, changing this:
    yield sock.sendto(msg, (host, port))
    to this:
    yield sock.sendto(msg.encode(), (host, port))
    resolves the issue. I'm guessing it is a similar situation with the following example.

    Running chat_server.py and chat_client.py:

    2013-04-06 15:33:14,872 - asyncoro - uncaught exception in server_proc:
    Traceback (most recent call last):
    File "/home/archie/Seteeri/server/asyncoro-1.3/examples/asyncoro.py", line 3212, in _schedule
    retval = coro._generator.throw(*exc)
    File "chat_server.py", line 40, in server_proc
    yield client.send_msg(msg)
    File "/home/archie/Seteeri/server/asyncoro-1.3/examples/asyncoro.py", line 3214, in _schedule
    retval = coro._generator.send(coro._value)
    File "/home/archie/Seteeri/server/asyncoro-1.3/examples/asyncoro.py", line 618, in _async_send_msg
    yield self.sendall(struct.pack('>L', len(data)) + data)
    TypeError: can't concat bytes to str

    Also Python 3.3 added a "new 'yield from' expression for generator delegation." I don't know if that would somehow be useful for asyncoro.

     
  • Giridhar Pemmasani

    I agree that the examples in asyncoro need to be altered to be usable with Python 3. However, asyncoro API should work under Python 3 just as socket API does, i.e., with Python 3 the callers should transfer bytes instead of strings.

    I don't (yet) see how asyncoro could use 'yield from', but interested to know others' ideas/suggestions.

     
    Last edit: Giridhar Pemmasani 2013-04-07
  • mahalin

    mahalin - 2013-04-07

    Other than that, everything else works well, though I'm still somewhat new to Python.

    I have one more question. In the second example here:
    http://asyncoro.sourceforge.net/examples.html

    How would you go about making the server asynchronous within the main thread (without the use of threads)?

    The Blender Game Engine uses logic ticks or a tickrate, meaning it executes code an arbitrary amount of times per second, 60 to be specific; it is a game loop. Previously using asyncore, instead of calling asyncore.loop(), I would use asyncore.poll() instead, which was executed 60 times a second. I didn't need asyncore.loop() as the main execution is already a game loop. Understandably, asyncore.loop() would block the game loop from continuing. I should mention, the game engine is also single-threaded.

    Another possible strategy comes from your other example towards the end of that page that uses queues so that I can queue/buffer incoming messages/data independently while the game loop takes them from the queue and processes them. Similar to this:
    http://stackoverflow.com/questions/6282978/writing-a-server-that-queues-tasks

    Of course, that'd mean both the server and the client would need a mediator/queue/buffer for when they're busy.

    Currently, I'm implementing IPC in the form of Unix Domain Sockets (I understand it might not make sense why for a game-type server). I do plan on implementing internet sockets also.

    One more thing:
    How would you compare asyncoro to bluelet?
    https://github.com/sampsyo/bluelet

    From what I can tell, asyncoro is more comphrehensive. Ah, nm scratch that question. Bluelet is too simple and thus lacking overall.

     
    Last edit: mahalin 2013-04-07
  • Giridhar Pemmasani

    I believe you mean 3rd example (now the examples are numbered, btw). There are two versions of server implementation; both use asyncoro.Coro for serving requests (and not threads).

    With asyncoro, the loop is implicit - the scheduler is initialized automatically when first coroutine is created (unless started explicitly, as exaplained in 'Distributed Programming' section) and continues to execute eligible coroutines, similar to the way operating system executes processes.

    I am not familiar with Blender Game Engine, so I guess you could either use queue (or some other data structure) for sending messages or use asyncoro's message passing (e.g., coro.send or channel.send which can be used from other threads) for both efficiency and simplicity. If you use latter approach, the game engine thread needs to know the Coro that processes the messages and whenever it wants to send a message, it can use 'send' method of that Coro - this approach will also work if game engine and Coro are on different machines (explained in 'Distributed Programming' section).

     
  • mahalin

    mahalin - 2013-04-09

    Thanks!

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks