Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve possible UnboundLocalError. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Archetrix
Copy link

Happened to me (see below). I know handling this case could be done different (stop/return after closing the socket probably), but my insight to the possible consequences is limited so i opted for the obvious solution to declare "bytes_written" ...

Traceback (most recent call last):
File "/usr/bin/parallel-ssh", line 119, in
do_pssh(hosts, cmdline, opts)
File "/usr/bin/parallel-ssh", line 110, in do_pssh
manager.run()
File "/usr/lib/pymodules/python2.6/psshlib/manager.py", line 67, in run
self.iomap.poll(wait)
File "/usr/lib/pymodules/python2.6/psshlib/manager.py", line 242, in poll
handler(fd, self)
File "/usr/lib/pymodules/python2.6/psshlib/askpass_server.py", line 77, in handle_write
buffer = buffer[bytes_written:]
UnboundLocalError: local variable 'bytes_written' referenced before assignment

Happened to me (see below). I know handling this case could be done different (stop/return after closing the socket probably), but my insight to the possible consequences is limited so i opted for the obvious solution to declare "bytes_written" ...

Traceback (most recent call last):
  File "/usr/bin/parallel-ssh", line 119, in <module>
    do_pssh(hosts, cmdline, opts)
  File "/usr/bin/parallel-ssh", line 110, in do_pssh
    manager.run()
  File "/usr/lib/pymodules/python2.6/psshlib/manager.py", line 67, in run
    self.iomap.poll(wait)
  File "/usr/lib/pymodules/python2.6/psshlib/manager.py", line 242, in poll
    handler(fd, self)
  File "/usr/lib/pymodules/python2.6/psshlib/askpass_server.py", line 77, in handle_write
    buffer = buffer[bytes_written:]
UnboundLocalError: local variable 'bytes_written' referenced before assignment
@quinkennedy
Copy link
Contributor

It seems to me that we should return at the end of the catch. But it is also good practice to declare variables before their use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants