threading supports the 'daemon' option[1], when set to True and the
program is in *foreground* then the event-loop thread dies when
SIGTERM-ed, however, if the program is in the *background* it doesn't
work! still deadlocked :'''(

while I'm not finding a definitive solution I'll be doing a
os.kill(os.getpid(), signal.SIGKILL) inside the finally block.

[1] https://docs.python.org/3.5/library/threading.html#threading.Thread.daemon

On Tue, Nov 24, 2015 at 4:46 PM, Marc Aymerich <glicer...@gmail.com> wrote:
> On Tue, Nov 24, 2015 at 4:29 PM, Marc Aymerich <glicer...@gmail.com> 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 <module>
>     time.sleep(10000)
> KeyboardInterrupt
> ^CException ignored in: <module 'threading' from
> '/usr/lib/python3.4/threading.py'>
> 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



-- 
Marc
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to