On 2014/06/18 03:53:36, GvR wrote: > I'm not sure I understand the reason for these ...
9 years, 10 months ago
(2014-06-18 09:24:34 UTC)
#2
On 2014/06/18 03:53:36, GvR wrote:
> I'm not sure I understand the reason for these changes. Why can't you have the
> current event loop be None in debug mode?
See my comment.
> Shouldn't the check-loop code be
> smarter rather than having to set the loop only in debug mode?
It's nice to be able to run tests with the event loop of the current policy to
set to None to check that the event loop is passed explicitly in asyncio.
In debug mode, it's not possible to use these checks because the event loop of
the current policy must be None. Otherwise, call_soon() and similar functions
fail (see the traceback in my comment).
https://codereview.appspot.com/110030043/diff/1/asyncio/proactor_events.py File asyncio/proactor_events.py (right): https://codereview.appspot.com/110030043/diff/1/asyncio/proactor_events.py#newcode404 asyncio/proactor_events.py:404: # from the event loop constructor On 2014/06/18 03:53:36, ...
9 years, 10 months ago
(2014-06-18 09:24:40 UTC)
#3
https://codereview.appspot.com/110030043/diff/1/asyncio/proactor_events.py
File asyncio/proactor_events.py (right):
https://codereview.appspot.com/110030043/diff/1/asyncio/proactor_events.py#ne...
asyncio/proactor_events.py:404: # from the event loop constructor
On 2014/06/18 03:53:36, GvR wrote:
> I don't understand this.
Example:
---
import socket
from asyncio.proactor_events import BaseProactorEventLoop
sock = mock.Mock(socket.socket)
proactor = mock.Mock()
ssock, csock = mock.Mock(), mock.Mock()
class EventLoop(BaseProactorEventLoop):
def _socketpair(s):
return (ssock, csock)
loop = EventLoop(proactor)
---
If the _debug set is initialized to True in the constructor, you get this
traceback:
---
Traceback (most recent call last):
File "x.py", line 14, in <module>
loop = EventLoop(proactor)
File "/home/haypo/prog/HG/tulip/asyncio/proactor_events.py", line 333, in
__init__
self._make_self_pipe()
File "/home/haypo/prog/HG/tulip/asyncio/proactor_events.py", line 403, in
_make_self_pipe
self.call_soon(self._loop_self_reading)
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 297, in
call_soon
return self._call_soon(callback, args, check_loop=True)
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 303, in
_call_soon
self._assert_is_current_event_loop()
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 319, in
_assert_is_current_event_loop
"non-threadsafe operation invoked on an event loop other "
RuntimeError: non-threadsafe operation invoked on an event loop other than the
current one
---
https://codereview.appspot.com/110030043/diff/1/asyncio/test_utils.py
File asyncio/test_utils.py (right):
https://codereview.appspot.com/110030043/diff/1/asyncio/test_utils.py#newcode390
asyncio/test_utils.py:390: # in debug mode, the current event loop is checked
On 2014/06/18 03:53:36, GvR wrote:
> This seems wrong.
If _debug is initialized to True in BaseEventLoop constructor and the event loop
of the current policy is set to None, calls to call_soon() (and similar
functions) fail. Example of traceback:
Traceback (most recent call last):
...
File "/home/haypo/prog/HG/tulip/asyncio/futures.py", line 301, in set_result
self._schedule_callbacks()
File "/home/haypo/prog/HG/tulip/asyncio/futures.py", line 211, in
_schedule_callbacks
self._loop.call_soon(callback, self)
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 298, in
call_soon
return self._call_soon(callback, args, check_loop=True)
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 304, in
_call_soon
self._assert_is_current_event_loop()
File "/home/haypo/prog/HG/tulip/asyncio/base_events.py", line 318, in
_assert_is_current_event_loop
if events.get_event_loop() is not self:
File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 503, in
get_event_loop
return get_event_loop_policy().get_event_loop()
File "/home/haypo/prog/HG/tulip/asyncio/events.py", line 449, in
get_event_loop
threading.current_thread().name)
AssertionError: There is no current event loop in thread 'MainThread'.
Issue 110030043: Enable debug mode of event loops when PYTHONASYNCIODEBUG is set
Created 9 years, 10 months ago by haypo_gmail
Modified 9 years, 10 months ago
Reviewers: GvR
Base URL:
Comments: 4