[issue34680] asyncio event_loop close fails off main thread if signal handler registered

2022-01-24 Thread Irit Katriel


Irit Katriel  added the comment:

The documentation should explicitly mention that an event loop should be 
accessed from only one thread (it hints at this by referring to "the loop of 
the current thread" but I don't see this stated clearly).

In the code, it would be good if multi-threaded access failed with a clearer 
error.

--
nosy: +iritkatriel
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34680] asyncio event_loop close fails off main thread if signal handler registered

2018-09-14 Thread epiphyte


Change by epiphyte :


--
nosy: +epiphyte

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34680] asyncio event_loop close fails off main thread if signal handler registered

2018-09-14 Thread Nic Watson


New submission from Nic Watson :

If a signal handler callback is registered on an event loop, and the event loop 
has close() called on it, the close will fail.

Exception:
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/nic/.pyenv/versions/3.7.0/lib/python3.7/threading.py", line 917, 
in _bootstrap_inner
self.run()
  File "/home/nic/.pyenv/versions/3.7.0/lib/python3.7/threading.py", line 865, 
in run
self._target(*self._args, **self._kwargs)
  File "/home/nic/tmp/signal_event_loop_bug.py", line 9, in do_loop
loop.close()
  File "/home/nic/.pyenv/versions/3.7.0/lib/python3.7/asyncio/unix_events.py", 
line 58, in close
self.remove_signal_handler(sig)
  File "/home/nic/.pyenv/versions/3.7.0/lib/python3.7/asyncio/unix_events.py", 
line 147, in remove_signal_handler
signal.signal(sig, handler)
  File "/home/nic/.pyenv/versions/3.7.0/lib/python3.7/signal.py", line 47, in 
signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

Code:
import asyncio
import signal
import threading

def mysighandler():
pass

def do_loop(loop):
loop.close()

loop = asyncio.new_event_loop()
loop.add_signal_handler(signal.SIGINT, mysighandler)
t = threading.Thread(target=do_loop, args=(loop,))
t.start()
t.join()

--
components: asyncio
messages: 325354
nosy: asvetlov, jnwatson, yselivanov
priority: normal
severity: normal
status: open
title: asyncio event_loop close fails off main thread if signal handler 
registered
type: behavior
versions: Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com