Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
64132014
Commit
64132014
authored
Mar 10, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup greenlet.py
parent
640867cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
31 deletions
+45
-31
gevent/greenlet.py
gevent/greenlet.py
+43
-30
setup.cfg
setup.cfg
+2
-1
No files found.
gevent/greenlet.py
View file @
64132014
...
...
@@ -24,7 +24,7 @@ __all__ = ['Greenlet',
if
PYPY
:
import
_continuation
import
_continuation
# pylint:disable=import-error
_continulet
=
_continuation
.
continulet
...
...
@@ -103,6 +103,7 @@ class _lazy(object):
class
Greenlet
(
greenlet
):
"""A light-weight cooperatively-scheduled execution unit.
"""
# pylint:disable=too-many-public-methods,too-many-instance-attributes
value
=
None
_exc_info
=
()
...
...
@@ -288,27 +289,29 @@ class Greenlet(greenlet):
result
+=
': '
+
formatted
return
result
+
'>'
_formatted_info
=
None
def
_formatinfo
(
self
):
try
:
return
self
.
_formatted_info
except
AttributeError
:
pass
info
=
self
.
_formatted_info
if
info
is
not
None
:
return
info
try
:
result
=
getfuncname
(
self
.
__dict__
[
'_run'
])
except
Exception
:
pass
else
:
args
=
[]
if
self
.
args
:
args
=
[
repr
(
x
)[:
50
]
for
x
in
self
.
args
]
if
self
.
_kwargs
:
args
.
extend
([
'%s=%s'
%
(
key
,
repr
(
value
)[:
50
])
for
(
key
,
value
)
in
self
.
_kwargs
.
items
()])
if
args
:
result
+=
'('
+
', '
.
join
(
args
)
+
')'
# it is important to save the result here, because once the greenlet exits '_run' attribute will be removed
self
.
_formatted_info
=
result
return
result
return
''
except
Exception
:
# pylint:disable=broad-except
# Don't cache
return
''
args
=
[]
if
self
.
args
:
args
=
[
repr
(
x
)[:
50
]
for
x
in
self
.
args
]
if
self
.
_kwargs
:
args
.
extend
([
'%s=%s'
%
(
key
,
repr
(
value
)[:
50
])
for
(
key
,
value
)
in
self
.
_kwargs
.
items
()])
if
args
:
result
+=
'('
+
', '
.
join
(
args
)
+
')'
# it is important to save the result here, because once the greenlet exits '_run' attribute will be removed
self
.
_formatted_info
=
result
return
result
@
property
def
exception
(
self
):
...
...
@@ -532,7 +535,7 @@ class Greenlet(greenlet):
try
:
result
=
self
.
_run
(
*
self
.
args
,
**
self
.
kwargs
)
except
:
except
:
# pylint:disable=bare-except
self
.
_report_error
(
sys
.
exc_info
())
return
self
.
_report_result
(
result
)
...
...
@@ -548,6 +551,8 @@ class Greenlet(greenlet):
Previously, if no callable object was passed to the constructor, the spawned greenlet would
later fail with an AttributeError.
"""
# We usually override this in __init__
# pylint: disable=method-hidden
return
def
rawlink
(
self
,
callback
):
...
...
@@ -559,7 +564,7 @@ class Greenlet(greenlet):
"""
if
not
callable
(
callback
):
raise
TypeError
(
'Expected callable: %r'
%
(
callback
,
))
self
.
_links
.
append
(
callback
)
self
.
_links
.
append
(
callback
)
# pylint:disable=no-member
if
self
.
ready
()
and
self
.
_links
and
not
self
.
_notifier
:
self
.
_notifier
=
self
.
parent
.
loop
.
run_callback
(
self
.
_notify_links
)
...
...
@@ -569,29 +574,34 @@ class Greenlet(greenlet):
The *callback* will be called with this instance as an argument
once this greenlet's dead. A callable is called in its own greenlet.
"""
# XXX: Is the redefinition of SpawnedLink supposed to just be an
# optimization, or do people use it? It's not documented
# pylint:disable=redefined-outer-name
self
.
rawlink
(
SpawnedLink
(
callback
))
def
unlink
(
self
,
callback
):
"""Remove the callback set by :meth:`link` or :meth:`rawlink`"""
try
:
self
.
_links
.
remove
(
callback
)
self
.
_links
.
remove
(
callback
)
# pylint:disable=no-member
except
ValueError
:
pass
def
link_value
(
self
,
callback
,
SpawnedLink
=
SuccessSpawnedLink
):
"""Like :meth:`link` but *callback* is only notified when the greenlet has completed successfully."""
# pylint:disable=redefined-outer-name
self
.
link
(
callback
,
SpawnedLink
=
SpawnedLink
)
def
link_exception
(
self
,
callback
,
SpawnedLink
=
FailureSpawnedLink
):
"""Like :meth:`link` but *callback* is only notified when the greenlet dies because of an unhandled exception."""
# pylint:disable=redefined-outer-name
self
.
link
(
callback
,
SpawnedLink
=
SpawnedLink
)
def
_notify_links
(
self
):
while
self
.
_links
:
link
=
self
.
_links
.
popleft
()
link
=
self
.
_links
.
popleft
()
# pylint:disable=no-member
try
:
link
(
self
)
except
:
except
:
# pylint:disable=bare-except
self
.
parent
.
handle_error
((
link
,
self
),
*
sys
.
exc_info
())
...
...
@@ -602,18 +612,21 @@ class _dummy_event(object):
def
stop
(
self
):
pass
def
start
(
self
,
cb
):
# pylint:disable=unused-argument
raise
AssertionError
(
"Cannot start the dummy event"
)
_cancelled_start_event
=
_dummy_event
()
_start_completed_event
=
_dummy_event
()
del
_dummy_event
def
_kill
(
g
reen
let
,
exception
,
waiter
):
def
_kill
(
glet
,
exception
,
waiter
):
try
:
g
reen
let
.
throw
(
exception
)
except
:
glet
.
throw
(
exception
)
except
:
# pylint:disable=bare-except
# XXX do we need this here?
g
reenlet
.
parent
.
handle_error
(
green
let
,
*
sys
.
exc_info
())
g
let
.
parent
.
handle_error
(
g
let
,
*
sys
.
exc_info
())
if
waiter
is
not
None
:
waiter
.
switch
()
...
...
@@ -647,7 +660,7 @@ def _killall3(greenlets, exception, waiter):
if
not
g
.
dead
:
try
:
g
.
throw
(
exception
)
except
:
except
:
# pylint:disable=bare-except
g
.
parent
.
handle_error
(
g
,
*
sys
.
exc_info
())
if
not
g
.
dead
:
diehards
.
append
(
g
)
...
...
@@ -659,7 +672,7 @@ def _killall(greenlets, exception):
if
not
g
.
dead
:
try
:
g
.
throw
(
exception
)
except
:
except
:
# pylint:disable=bare-except
g
.
parent
.
handle_error
(
g
,
*
sys
.
exc_info
())
...
...
setup.cfg
View file @
64132014
[pep8]
# N801: class names should use CapWords
# N802: function names should be lower-case; comes from Windows funcs
ignore=E702,E265,E402,E731,E266,E261,W503,E129,N801,N802
# N803: argument name should be lower-case; comes up with using the class name as a keyword-argument
ignore=E702,E265,E402,E731,E266,E261,W503,E129,N801,N802,N803
max_line_length=160
exclude=.runtimes,.eggs,.tox,.git,build,2.6,2.7,2.7pypy,3.3,3.5,test_support.py,test_queue.py,patched_tests_setup.py,test_threading_2.py,lock_tests.py,_sslgte279.py,3.4
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment