I try to make a simple voice dialing script that should run from hot key in Ubuntu and after recognition return value to clipboard. When I start it from shell, all work as expected. But when I'm trying to use hot key, I got a very strange (on my opinion) behavior that I cannot to understand.For recognition I use online service available through grpc.
So here is a code example:
if __name__ == '__main__': if is_pid_file_exist: # here I remove a pid file else: # here some code for make a connection and sending data for recognition # and the next block (with problem) should process response try: for r in it: event_type, alternatives = r.WhichOneof('Event'), None if event_type == 'final_refinement': alternatives = [a.text for a in r.final_refinement.normalized_text.alternatives] recognition = ''.join(alternatives) if len(alternatives[0])>1 else recognition print(f'type={event_type}, alternatives={alternatives}') except grpc._channel._Rendezvous as err: print(f'Error code {err._state.code}, message: {err._state.details}') raise err
The strange behavior is that all else branch do not work when try-except block uncommented. Even print do not print else.
From hot key start a bash script like this:
#!/bin/bashcd /home/user/script-folder/python3 recognition.py &>> log/recognition.log
So I use shell outputs for logging.
Well, the cherry on the cake: I am new in python.
I tried:
- comment blocks of code in else branch. So I understand that a mistake around this block of code
- tear of paths, permissions, environments python version and other - no differences