top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Python: Cannot step through asynchronous iterator manually

+1 vote
247 views

To loop though an iterator one usually uses a higher-level construct such as a 'for' loop. However, if you want to step through it manually you can do so with next(iter).

I expected the same functionality with the new 'asynchronous iterator' in Python 3.5, but I cannot find it.

I can achieve the desired result by calling 'await aiter.__anext__()', but this is clunky.

Am I missing something?

posted Jan 30, 2016 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

If I have a string that is python code, for example

mycode = "print('hello world')"
myresult = "hello world"

How can a "manually" build a unittest (doctest) and test I get myresult

I have attempted to build a doctest but that is not working.

e = doctest.Example(source="print('hello world')/n", want="hello worldn")
t = doctest.DocTestRunner()
t.run(e)
+2 votes

The problem description:

There are set of processes running on my system say process_set_1. Build a process agent which runs an asynchronous socket listening to incoming requests from process_set_1. Each process sends an id. The agent stores these ids in a dictionary and sends response that ur id has been accepted. Now agent process receives some data from another process (which is some sort of sister process for the agent). This data contains id along with a command which is to be sent by the agent to the process_set_1 through HTTP client over AF_UNIX socket, since each process in process_set_1 has a HTTP listening CLI. The process agent sends an HTTP request by recognizing id stored in dictionary to the process_set_1. A service running in the process_set_1 routes this HTTP command to the respective process.

Now my problem is the HTTP request which to be sent must go through AF_UNIX socket. I got this solution.

class UnixStreamHTTPConnection(httplib.HTTPConnection):

    def __init__(self, path, host='localhost/rg_cli',port=None, strict=None,
                 timeout=None):
        httplib.HTTPConnection.__init__(self, host, port=port, strict=strict,
                                        timeout=timeout)
        self.path=path

    def connect(self):
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.sock.connect(self.path)

But this cannot work since normal socket will not work and thus i thought of asyncore module in python. To use asyncore module again i will have to subclass asyncore.dispatcher. This class also contains connect() method.

Another problem is I don't know how asyncore module works and thus not able to find a way to mix the work of 1) listening forever, accept the connection, store id and the sock_fd.
2) accept data from the process' agent sister process, retrieve the sock_fd by matching the id in the dictionary and send it through the AF_UNIX socket.

Please help since i have already spent 2 days digging it out. Sorry if could explain my problem very well.

0 votes
while len(word_letters) > 0 and lives > 0:
        # letters used
        # ' '.join(['a', 'b', 'cd']) --> 'a b cd'
        print('You have', lives, 'lives left and you have used these letters: ', ' '.join(used_letters))

        # what current word is (ie W - R D)
        word_list = [letters if letters in used_letters else '-' for letters in word]
        print(lives_visual_dict[lives])
        print('Current word: ', ' '.join(word_list))

https://www.youtube.com/watch?v=8ext9G7xspg
the part which i am finding difficult to understand appears at 32:15 of the above video.
i don't know how to highlight a part of a code while posting a question on this forum. this is my first post.
if someone can help than i would be very grateful.

+1 vote

I am trying to run a Python script and I get the error message: "Cannot find GStreamer Python Library". I have Windows XP. I tried uninstalling and re-installing GStreamer but that didn't fix the error message. I installed the complete version of GStreamer. Anybody have any ideas of things to try to fix this? Is there a Python file that looks for the location of GStreamer that I can edit to point to the correct location?
I am using Python 27.

+2 votes

I know basic of python and I have an xml file created from csv which has three attributes "category", "definition" and "definition description". I want to parse through xml file and identify actors, constraints, principal from the text.

However, I am not sure what is the best way to go. Any suggestion?

...