Python Forum
Why does this hang the system up
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does this hang the system up
#1
Thiese two examples seem to hang up the system.

raise FoundException("""\n\nYour password is:\n%s""" % o)
there seems to be no def for it.

in another code example, there is a def and it looks like this:

class FoundException(Exception):
    pass
.
.
.
raise FoundException("""\n\nYour password is:\n%s""" % o)
if the program has reached the point to raise this exception, the program has done it's work and could be ended.

please suggest a way to handle this that will not hang the system up.
Reply
#2
Doesn't hang the system for me. Does it really hang the whole system for you? Or is just the program? Have you tried to add a \n at the end of the format string?
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#3
It seems to not allow me to do anything else on the desktop. The mouse still moves as it should and that is about it.

Here is what it says

  71         return ""
     72     try:
     73         o = decode_keystore_json(w,pw)
     74         print(o)
     75         # print (pw)q
---> 76         raise PasswordFoundException("MY**") #("""\n\nYour password is:\n%s""" % o)
        
     77     except ValueError as e:
     78         # print(e)
     79         return ""
     80             

NameError: name 'PasswordFoundException' is not defined
I hit control C and it let me close the program once. Other times it would not.
Reply
#4
We have not seen the rest of your code and the problem could likely be there. When the exception is raised, it can be caught somewhere, so it all depends what happens then.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#5
If I hit control C multiple times it will finally stop the program. It just takes a while.
Since I now have access to the terminal output I can see there are multiple exception messages.
Perhaps ten or more I think coming from LIB functions and not my code.
Here is a typical example:
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/joblib/_parallel_backends.py", line 350, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/joblib/parallel.py", line 131, in __call__
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "/usr/local/lib/python3.5/dist-packages/joblib/parallel.py", line 131, in <listcomp>
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
  File "pyethrecover3.py", line 79, in attempt
    raise PasswordFoundException("Password Found")
PasswordFoundException: Password Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/lib/python3.5/dist-packages/joblib/_parallel_backends.py", line 359, in __call__
    raise TransportableException(text, e_type)
joblib.my_exceptions.TransportableException: TransportableException
___________________________________________________________________________
PasswordFoundException                             Thu Jun  8 07:14:19 2017
PID: 2409                                    Python 3.5.2: /usr/bin/python3
I suspect that one of the problems may be that the exception is raised from inside a for loop and the loop has to be stopped first. I know that in a Windows program using C# trying to exit a program from inside a loop will cause similar problems.

Here is the loop:

Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds)
It seems to be a combo statement and could it be broken down into separate statements so I will understand it better. I know so little about python syntax.
Reply
#6
Well, we still haven't see all your code. From what I see, the exception could be raised in a subprocess. This stops the subprocess but not the main which could be starting more subprocesses.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#7
Does this help?

class PasswordFoundException (Exception):
    pass

def attempt(w, pw):
    
    # sys.stdout.write("\r")

    # sys.stdout.write("\rAttempt #%d: %s" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string
    sys.stdout.write("Attempt #%d: %s\n" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string

    sys.stdout.flush()
    #print(counter.value)
    counter.increment()

    if len(pw) < 10:
        return ""
    
    try:
        o = decode_keystore_json(w,pw)
        print("Password is: ", pw, "   ", o)
        
        raise PasswordFoundException("Password Found")
        
    except ValueError as e:
        # print(e)
        return ""

class Counter(object):
    def __init__(self):
        self.val = multiprocessing.Value('i', 0)

    def increment(self, n=1):
        with self.val.get_lock():
            self.val.value += n

    @property
    def value(self):
        return self.val.value

def __main__():
    global counter
    counter = Counter()
    pwds = []
    pwds = itertools.chain(pwds, generate_all(grammar,''))

    try:
        Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds)

    except Exception as e:
        traceback.print_exc()
        while True:
            sys.stdout.write('\a')
            sys.stdout.flush()

if __name__ == "__main__":
    __main__()
Reply
#8
(Jun-08-2017, 01:02 PM)Able98 Wrote: Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds)
What is Parallel? What's delayed?
delayed looks like a decorator, but what does it do?


From that line, my guess is that you're creating a single spare process, which is passed a generator of attempted passwords. Although hopefully that's not the case, since attempt uses global variables and writes to sys.stdout.
Reply
#9
(Jun-08-2017, 04:46 PM)nilamo Wrote:
(Jun-08-2017, 01:02 PM)Able98 Wrote: Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds)
What is Parallel?  What's delayed?
delayed looks like a decorator, but what does it do?

From that line, my guess is that you're creating a single spare process, which is passed a generator of attempted passwords.  Although hopefully that's not the case, since attempt uses global variables and writes to sys.stdout.

As I understand it, the Parallel does parallel processing and is part of the joblib library. I had hoped those here would know more than I.

If I understand you correctly, I will replace sys.stdout stuff with "print" and rename the attempt procedure.

My main suspect is the for loop which I would like to rewrite and have the attempt procedure set a flag for it to stop and exit. I do not see where the "raise PasswordFoundException call is needed at all and as I see it causing the problem. Please suggest a way to rewrite the for loop.
Reply
#10
(Jun-08-2017, 07:07 PM)Able98 Wrote: is part of the joblib library. I had hoped those here would know more than I.

Just because we know python, doesn't mean we know all of the 3rd party packages that have ever been written for it :p

Is there a reason you're using a process? Was it not fast enough to just run it normally?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,604 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  multiprocess hang when certain number is used in the program esphi 7 3,177 Nov-06-2020, 03:49 PM
Last Post: esphi
Question Difference between Python's os.system and Perl's system command Agile741 13 6,799 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Hang man game supermane 2 2,240 Aug-15-2018, 12:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020