Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Marc Aymerich Newsgroups: comp.lang.python Subject: Re: Futex hang when running event loop on a separated thread Date: Tue, 24 Nov 2015 21:17:02 +0100 Lines: 79 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de JZL2q+MTwKHuUL07l97N+AORc1Lk8VGxPGZm4OhnZ2+Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'finally:': 0.05; 'sys': 0.05; '__name__': 0.07; 'differently': 0.07; 'implements': 0.07; 'skip:/ 10': 0.07; 'works.': 0.07; 'cc:addr:python-list': 0.09; '0.1': 0.09; 'behave': 0.09; 'directions': 0.09; 'grep': 0.09; 'mkdir': 0.09; 'thread': 0.10; 'python': 0.10; 'def': 0.13; "'__main__':": 0.16; '24,': 0.16; 'aux': 0.16; 'fix,': 0.16; 'fuse': 0.16; 'osx': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reproduce': 0.16; 'stuff,': 0.16; 'subject:when': 0.16; 'sudo': 0.16; 'threading': 0.16; 'wrote:': 0.16; 'ssl': 0.18; 'try:': 0.18; 'python?': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'null)': 0.22; 'appears': 0.23; 'bit': 0.23; 'tried': 0.24; 'import': 0.24; 'patch': 0.24; 'header:In-Reply-To:1': 0.24; 'install': 0.25; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'idea': 0.28; '0.5': 0.29; 'marc': 0.29; "i'm": 0.30; 'url:mailman': 0.30; 'operations': 0.31; 'another': 0.32; "can't": 0.32; 'maybe': 0.33; 'url:python': 0.33; 'evolving': 0.33; 'null': 0.33; 'ubuntu': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'tue,': 0.34; 'server': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'version': 0.38; 'received:209': 0.38; 'thank': 0.38; 'why': 0.39; 'url:mail': 0.40; 'still': 0.40; 'some': 0.40; 'hang': 0.60; 'waiting': 0.60; 'your': 0.60; 'confirm': 0.62; 'fire': 0.63; 'more': 0.63; 'between': 0.65; 'here': 0.66; '12:37': 0.84; 'to:none': 0.91; 'interrupt': 0.91; 'ware': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc :content-type; bh=HqY+MyvPE8EVKWTS36GxgUkp0yXY7yw7xoZOMphWrCg=; b=cX5KxnZel5pKKSvHOSX2n5krV0MTXR7tD0ZSUvUF195PWJ/yMgj4DB9mlFvCy9662b WppmRhXV1Cf4StA9k991IviBJ8bmzNzIh1g/P+D/3TyvYQVz0o7VvfNbW3zVU7eDEaEN EwWXf4kjTX9f3G352dT3wGqba2mAF/0X9hf432tLKtL2ZR1DV9C+r/QXWM9x8EKmO/RB seRw0p4m+bkomseFKARecT/Dv2bTx1Gtpmse00Gf1prk5bhA83WPVcHJ3WDcxUNVXDvZ 6KOtFy4T7CqDNAYVv/82Itckh1jRjg1BZARbP0HJrGzlcfAIKBn6FTJKmibs1Z0XrSuW tNCQ== X-Received: by 10.50.62.104 with SMTP id x8mr326262igr.22.1448396241746; Tue, 24 Nov 2015 12:17:21 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99392 On Tue, Nov 24, 2015 at 8:41 PM, Zachary Ware wrote: > On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich wrote: >> still it appears to work only if the main thread is in the foreground >> (as of calling Thread() with deamon=True), I don't get why it behaves >> differently :( maybe it is waiting for other stuff, but no idea how to >> confirm this with strace of other means.. i always see the same >> 'futex(0x7f9a70000c10, FUTEX_WAIT_PRIVATE, 0, NULL' > > What's your exact version of Python? asyncio is still evolving > rapidly, and may behave differently between patch releases (say, > between 3.4.1 and 3.4.3). > > I have tried out your reproducer with my fix, and I can't provoke a > hang using Python 3.4.3 on either OSX or Ubuntu Trusty. Can you give > some more specific directions to reproduce? > > -- > Zach > -- > https://mail.python.org/mailman/listinfo/python-list Yep, I'm a bit lost about how fuse implements going into background... so the only way I have to reproduce this so far is by using fuse :( # pip3 install fusepy import asyncio import threading import time import os import sys from fuse import FUSE, Operations def run_loop(loop_container): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) coro = asyncio.start_server(lambda: 1, '0.0.0.0', 8888, loop=loop) server = loop.run_until_complete(coro) loop_container['loop'] = loop loop.run_forever() if __name__ == '__main__': mountpoint = sys.argv[1] loop_container = {} handler = threading.Thread(target=run_loop, args=(loop_container,)) handler.start() try: # with foreground=True works FUSE(Operations(), mountpoint, foreground=False) finally: loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop) $ mkdir /tmp/7777 $ python3.5 /tmp/eventtest.py /tmp/7777 # Another terminal $ ps aux | grep python3.5 glic3 19983 0.5 0.1 215540 10772 ? Ssl 21:05 0:00 python3.5 me.py /tmp/7777 $ sudo strace -p 19983 Process 19983 attached - interrupt to quit futex(0x7fff42affca0, FUTEX_WAIT_PRIVATE, 0, NULL) = 0 # Here i fire $ fusermount -u /tmp/7777 tgkill(19983, 19985, SIGRTMIN) = 0 futex(0x7fff42affc30, FUTEX_WAKE_PRIVATE, 1) = 0 futex(0x7f9840afc9d0, FUTEX_WAIT, 19984, NULL I've just tried with python3.5 and the same behavior. The thing is that with foreground=True it just works. thank you for your time! -- Marc