Path: csiph.com!news.swapon.de!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 16:46:15 +0100 Lines: 80 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de BmBA5MoLC+RKvhLP4EVf7wm9W4vXle8MeFZz1stE7ASw== 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; 'elif': 0.04; 'handler': 0.04; 'finally:': 0.05; 'ignored': 0.05; 'python3': 0.05; '__name__': 0.07; 'exit': 0.07; 'skip:/ 10': 0.07; 'valueerror:': 0.07; '22,': 0.09; '__init__': 0.09; 'thread': 0.10; 'def': 0.13; "'__main__':": 0.16; '24,': 0.16; 'deadlock': 0.16; 'fuse': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:when': 0.16; 't.join()': 0.16; 'threading': 0.16; 'timeout):': 0.16; 'wrote:': 0.16; 'try:': 0.18; '2015': 0.20; 'skip:" 30': 0.20; 'skip:" 40': 0.20; 'appears': 0.23; 'second': 0.24; 'tried': 0.24; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'skip:" 20': 0.26; 'skip:_ 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'idea': 0.28; 'marc': 0.29; 'separated': 0.29; 'thread,': 0.29; 'run': 0.33; 'null': 0.33; 'traceback': 0.33; 'tue,': 0.34; 'file': 0.34; 'running': 0.34; 'server': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'waiting': 0.60; 'situation': 0.67; '4:29': 0.84 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:to :content-type; bh=qt5VO95+XPxbUcEpE9+YUzfo1IWSelh2GpaGki2Nl7k=; b=vW0Id/oP/qsRq5IxJ6S6FklqLRteN2WsNZnCWIJzur4xV8IERoBmxCn7GS88qEP3n0 sDbEwkyqwyQGhTQE8CKC37b+KRjvA+F368BXUpfTJFYpD7imiWopKBANF8p2eqdDZU3y Z+gt+JoFc14vrQJrz7FIzbfU7qUT4r0bj8tj6Ow6LevwZrE+HWeauHN8VJS/lw+Px4q/ ZOiONLInlc/v9i3OTZiFhrXB+cWaaKKoMSTlsSU6NJtp5bXe3asZ2FBzpE+Onvnjh5Nc cR0kpfsHWNo7KZm+w1hMgRJ3ib/gJ7MK1eVAl/1zP64sE+dKm6uh+US3SMALX60ONg/s bqqw== X-Received: by 10.50.182.7 with SMTP id ea7mr20025702igc.2.1448379995372; Tue, 24 Nov 2015 07:46:35 -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:99359 On Tue, Nov 24, 2015 at 4:29 PM, Marc Aymerich wrote: > Hi, > > I have to run the asyncio.loop on a separated thread because the main > thread is running FUSE. Apparently fuse needs to run on the main > thread because it uses signal(): > > .... > File "/usr/local/lib/python3.4/dist-packages/fuse.py", line 390, in __init__ > old_handler = signal(SIGINT, SIG_DFL) > ValueError: signal only works in main thread > > > Anyway, when I exit the program it appears that i run into a deadlock > with the eventloop thread, strace is stuck with: > > .... > futex(0x7f7ba0000c10, FUTEX_WAIT_PRIVATE, 0, NULL > > > I've tried to stop the event loop from the main thread but the > situation is exactly the same :( > > loop_container = {} > handler = threading.Thread(target=run_loop, args=(loop_container,)) > try: > handler.start() > FUSE(fs) > finally: > loop_container['loop'].stop() > # handler.join() > > Any idea on how I can shutdown the hole thing? I have to manually kill > the program each time :( this can be reproduced with the following program: import asyncio import threading import time 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__': loop_container = {} handler = threading.Thread(target=run_loop, args=(loop_container, )) handler.start() try: time.sleep(10000) finally: loop_container['loop'].stop() glic3@XPS13:/tmp$ python3 /tmp/eventtest.py ^CTraceback (most recent call last): File "/tmp/eventtest.py", line 22, in time.sleep(10000) KeyboardInterrupt ^CException ignored in: Traceback (most recent call last): File "/usr/lib/python3.4/threading.py", line 1294, in _shutdown t.join() File "/usr/lib/python3.4/threading.py", line 1060, in join self._wait_for_tstate_lock() File "/usr/lib/python3.4/threading.py", line 1076, in _wait_for_tstate_lock elif lock.acquire(block, timeout): KeyboardInterrupt it is waiting for tstate_lock in the second ^C -- Marc