Trent Nelson avatar Trent Nelson committed 948c578 Draft

Checkpoint.

Comments (0)

Files changed (1)

 Twisted could be written to leverage the new capabilities quite
 easily.  This applies to any other event loops like Tornado et al.
 
+XXX TODO
+========
+Example Python Code Using New Parallel Primitives
+-------------------------------------------------
+I haven't thought much about what the new parallel primitives will
+look like from a syntactical perspective.  I'm confident that the most
+elegant solution will naturally present itself as part of subsequent
+PEP reviews.
+
+The primary goal of this PEP is to introduce the concept of parallel
+primitives.  Such primitives have well defined entry and exit points,
+which the main interpreter thread relies upon to control parallel
+execution contexts.
+
+There are two use cases that need to be catered for: event-driven
+client/server programs and parallel task/data decomposition.
+
+A possible example of what the former would look like::
+
+    class SimpleEchoServer(async.TCPServer):
+        def __init__(self, cb):
+            cb.success = self.connection_established
+            async.accept(self.sock, cb)
+
+        @parallel.event
+        def connection_established(self, cb):
+            cb.success = self.line_received
+            async.expect_line(self.sock, cb)
+
+        @parallel.event
+        def line_received(self, data, cb):
+            cb.success = self.connection_established
+            async.write(self.sock, data, cb)
+
+    server = SimpleEchoServer()
+    async.register(server)
+    async.run()
+
+The parallel task/data decomposition primitives will probably share
+some similarities with the OpenMP-style of interface, as it's well
+suited to this sort of task::
+
+    @parallel.map
+    def linelen(line)
+        return len(line)
+
+    # Runs linelen(line) in parallel against each sequence
+    # element in ``lines``, then sums the result.
+    total = parallel.reduce(text.splitline(), lenline, lambda i: i+1)
+
+Underlying Implementation of Async Facade
+-----------------------------------------
+More discussion is warranted regarding how the async facade would be
+implemented on different platforms.  POSIX platforms will use epoll
+or kqueue, falling back to poll.  Windows, AIX and Solaris can use
+their native AIO facilities with IOCP or event ports.
+
+How each underlying implementation interacts with the parallel
+primitives also needs to be discussed.  Are separate threads used, is
+it all done in the main thread during parallel breaks, etc.
 
 References
 ==========
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.