Message from discussion
Using greenlets in 2 separate threads
network library" <gevent@googlegroups.com>
Received: by 10.224.180.141 with SMTP id bu13mr15188942qab.2.1351699303027;
Wed, 31 Oct 2012 09:01:43 -0700 (PDT)
X-BeenThere: gevent@googlegroups.com
Received: by 10.224.195.196 with SMTP id ed4ls3025008qab.0.gmail; Wed, 31 Oct
2012 09:01:40 -0700 (PDT)
Received: by 10.66.81.98 with SMTP id z2mr12126222pax.19.1351699300019;
Wed, 31 Oct 2012 09:01:40 -0700 (PDT)
Received: by 10.66.81.98 with SMTP id z2mr12126221pax.19.1351699300006;
Wed, 31 Oct 2012 09:01:40 -0700 (PDT)
Return-Path: <ams....@gmail.com>
Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48])
by gmr-mx.google.com with ESMTPS id uz6si1001163pbc.0.2012.10.31.09.01.39
(version=TLSv1/SSLv3 cipher=OTHER);
Wed, 31 Oct 2012 09:01:40 -0700 (PDT)
Received-SPF: pass (google.com: domain of ams....@gmail.com designates 209.85.220.48 as permitted sender) client-ip=209.85.220.48;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ams....@gmail.com designates 209.85.220.48 as permitted sender) smtp.mail=ams....@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pa0-f48.google.com with SMTP id kp12so1110791pab.35
for <gevent@googlegroups.com>; Wed, 31 Oct 2012 09:01:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject
:references:in-reply-to:content-type:content-transfer-encoding;
bh=83eAN7CqSKL5B6kU4iSxkoojodLzTrnU9kriwiDZnlo=;
b=GIzlqzKZuYYLXEAAbvn2qeohd80cRER7EQQhQm492ergPKcSV+3I0gARS4DGuw/tck
5+csAFppOUr1XbFPt8IblXog9lB28PH/QgTRtWh8i3Ri9VFFaWb6O0QsUoQP6WC6Qt3q
rsk0Uiejwkkn88tKNziSBsfIJBJuua7E1x7SY+eC93y/N2yLz4Vqzs2dmDZBro+m3TLe
MaI9uU0QnLTPIRCHNO9VfOTunQtieyWI8JWgGSKGOQEjwvDk4aYy0zlbkrbMKJL7mI4f
gqVE6N0UdYuJGCuh1K+kX0K3wWOcr5FNbIh7HBnIHVmQ/2foJERGDutHMlOPqdpQxBNK
77QQ==
Received: by 10.66.72.134 with SMTP id d6mr103275732pav.13.1351699299735;
Wed, 31 Oct 2012 09:01:39 -0700 (PDT)
Return-Path: <ams....@gmail.com>
Received: from [192.168.1.107] (c-24-6-128-40.hsd1.ca.comcast.net. [24.6.128.40])
by mx.google.com with ESMTPS id un16sm2480878pbc.47.2012.10.31.09.01.37
(version=SSLv3 cipher=OTHER);
Wed, 31 Oct 2012 09:01:38 -0700 (PDT)
Sender: Aseem Mohanty <aseem.moha...@gmail.com>
Message-ID: <50914B61.5060...@gmail.com>
Date: Wed, 31 Oct 2012 09:01:37 -0700
From: AM <ams....@gmail.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version: 1.0
To: gevent@googlegroups.com
CC: Viatcheslav Gachkaylo <vgachka...@crystalnix.com>
Subject: Re: [gevent] Using greenlets in 2 separate threads
References: <2c628dae-31a2-48d1-8b8f-2851894da685@googlegroups.com>
In-Reply-To: <2c628dae-31a2-48d1-8b8f-2851894da685@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
On 10/30/2012 11:25 PM, Viatcheslav Gachkaylo wrote:
> Hello,
>
> I need to run 2 servers communicating with each other in a single
> process. One uses gevent event loop, the other one uses tornado.
> Now I run the 2nd server in a separate threading.Thread. However I
> wish to use greenlets in the code of this second server. Will this
> cause any troubles?
> What is a simple yet effective alternative in this situation? How hard
> it is to make tornado use gevent and unite the servers' run loops
> together?
> I don't think dividing into 2 different processes with a proper
> communication between them is an appropriate solution.
>
> The first server is gevent.wsgi.WSGIServer, the second one
> is https://github.com/thisismedium/python-xmpp-server/
>
> --
> Thank you,
> Viatcheslav Gachkaylo
> Crystalnix
Hi Vitaly.
If you want to run two servers in the same process, simply start the
servers using start (not serve_forever) and wait on the two greenlet
objects you get back. You will have to take care that when one of them
terminates the other one terminates too, or else you may end up with
only one server running.
Re: tornado, it uses its own event loop based around the same apis that
gevent uses but at a much lower level. In theory you might be able to
make it work with greenlets, but you may end up recreating gevent :)
I am wondering why two processes are not a good model?
HTH
AM