Community
    • Login

    End python script execution

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    pythonscript
    5 Posts 2 Posters 732 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • claudio pergolinC
      claudio pergolin
      last edited by

      hi everyone, having to process a fairly long text file with python script and taking a long time, I never know if at that moment, the processing of the file by npp has come to an end or not. To solve this unknown at the end of my script I added the instruction

      notepad.messageBox (" Finished !! "," Script ")"
      

      However, this did not solve the problem for me because, after the display of the end of execution message, if I try to restart the same script again, npp tells me that the document has been modified again. Obviously, the display of the popout does not “repeat” the completion of the previous instructions. How can I solve it? Thanks

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @claudio pergolin
        last edited by

        @claudio-pergolin ,

        I’m not sure you’ve explained your problem well enough for us to understand what’s happening to you, or be able to help you debug it.

        if I try to restart the same script again, npp tells me that the document has been modified again.

        For example, I don’t understand this. Having a modified document doesn’t prevent a script from running. If your script modifies your document but doesn’t save it, then running the script again would obviously be in a state of the file being modified.

        Obviously, the display of the popout does not “repeat” the completion of the previous instructions.

        I’m not sure what this is trying to say.

        You’re going to have to give us more to go on for us to be able to help you. Sorry.

        1 Reply Last reply Reply Quote 2
        • claudio pergolinC
          claudio pergolin
          last edited by

          My script performs the function of replacing some terms present in the original document with new terms. Once the script has been started and finished, depending on the appearance of the warning window at the end of the script, clearly due to the last command line in order of execution of my script:

          command 1
          command 2
          ...
          notepad.messageBox ("Finished !!", "Title Window") 
          
          

          I expect that ALL the necessary REPLACEMENTS have been made. Therefore, once I have saved the changes and restarted the same scrip on the document just edited and saved, npp warns me, with the change of status of the “save” icon in the toolbar tools that a further change has been made to the document.
          I conclude that, when the “finished!” of the FIRST time I ran my script does not correspond to a real end of this but that the command interpreter executes the various commands in succession without waiting for the end of the previous ones and that when “Finished” appears the script is still in execution.
          Question: how can I do so that the window at the end of the script appears to me at a real end of the execution of the latter?
          I hope I was at least a little clearer.
          thank you

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @claudio pergolin
            last edited by

            @claudio-pergolin ,

            You were slightly clearer, but you have still given us nothing to base a reply on.

            Most commands in PythonScript are sequential, and should not allow the script to continue until the action has finished (except for callback related ones, I don’t know of any that aren’t, but I could be wrong).

            I just ran an experiment where my script was just a simple call to time.sleep(60), and tried to run that script twice in quick succession (so the first instance wasn’t done before the second was started; I gave myself 60 sec so that “quick” was easily doable, even with menu entries). When I tried the second instance, I got

            925729db-f81b-424c-8e4c-3136667547c5-image.png

            So if PythonScript is truly in the middle of running the script still, it will not allow the new script to run. So I believe quite strongly that the script is not still executing.

            So in explicit answer to your

            Question: how can I do so that the window at the end of the script appears to me at a real end of the execution of the latter?

            It is impossible to run a new script while the current script is still executing.

            Going back to your actual problem:

            I expect that ALL the necessary REPLACEMENTS have been made. Therefore, once I have saved the changes and restarted the same scrip on the document just edited and saved, npp warns me, with the change of status of the “save” icon in the toolbar tools that a further change has been made to the document.

            You mention that your script does search-and-replace. Then I interpret your phrasing that after the script is done, you manually save. Then you run the same script with a search-and-replace, and Notepad++ tells you that the file is again modified. This tells me that the search-and-replace still finds matching text on the second run, and is able to make replacements again, thus telling Notepad++ that you have unsaved changes. Which, in the described circumstances, you do. I wonder if maybe the search-and-replace you ran just did a single replacement rather than “replace all”. Or maybe something about the second state is still able to match your search expression, even though it did make all the initial replacements.

            But since you seem unwilling to share an example of code that actually shows the problem, we’re not going to be able to do much to help you debug, and all we can do is make vague guesses. Good luck.

            1 Reply Last reply Reply Quote 2
            • claudio pergolinC
              claudio pergolin
              last edited by

              i resolved. thank you

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors