Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Answering your last question: It does! But, IMHO, the question is: does it makes sense mix Events and Threads? You can check this article about hybrid concurrency models: <a href="http://bibliotecadigital.sbc.org.br/download.php?paper=3027" rel="nofollow">http://bibliotecadigital.sbc.org.br/download.php?paper=3027</a></p> <p>My tip: Start with just one process and an event loop, like in the tulip model. I'll try to explain how can you use tulip to have Events+async I/O (and threads or other processes) without callbacks at all.</p> <p>You could have something like <code>accept = yield from check_incoming()</code>, which should be a tulip coroutine (check_incoming), and inside this function you could use <code>loop.run_in_executor()</code> to run your graph search in a thread/process pool (I'll explain more about this later). This function <code>run_in_executor()</code> returns a Future, in which you can also <code>yield from tasks.wait([future_returned_by_run_in_executor], loop=self)</code>. The next step would be <code>result = future_returned_by_run_in_executor.result()</code> and finally return <code>True</code> or <code>False</code>.</p> <p>The process pool requires that only pickable objects can be executed and returned. This requirement is not a problem but it's implicit that the graph operation must be self contained in a function and must obtain the graph instance somehow. The Thread pool has the GIL problem since you mentioned CPU bound tasks which can lead to 'acquiring-gil-conflicts' but this was improved in the new Python 3.x GIL. Both solutions have limitations..</p> <p>So.. instead of a pool, you can have another single process with it's own event loop just to manage all the graph work and connect both processes with a unix domain socket for instance..</p> <p>This second process, just like the first one, must also accept incoming connections (but now they are from a known source) and can use a thread pool just like I said earlier but it won't "conflict" with the first event loop process(the one that handles external clients), only with the second event loop. Threads sharing the same graph instance requires some locking/unlocking. </p> <p>Hope it helped!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload