Subprocess maximum recursion depth exceeded











up vote
0
down vote

favorite












I am trying to current playing track name from Spotify desktop app window title by using subprocess. In generally, my code is working. But when trying to retrieve song name each five second, i get RecursionError. Where is the problem?



Code1



def title_of_window(self,window_class):
"""
Retrieves the title of application by through 'subprocess'.

Params:
window_class (string) -- name of the application to be taken the title
ex. --> spotify
--> filezilla
--> putty
--> atom

For this app:
- window_class parameter must be equal to "spotify"
- Retrieves the current playing song name from Spotify.

"""
# Finds id of all GUI apps who running.
# Ex. -> ['0x200000a', '0x3800007', '0x4800001', '0x2e00010', '0x3600001n']
active_windows = subprocess.Popen(["xprop",
"-root",
"_NET_CLIENT_LIST_STACKING"],
stdout=subprocess.PIPE).communicate()
active_windows_ids = active_windows[0].decode("utf-8").split("# ")[1].split(", ")
#
# Sends all ids to 'xprop -id' and checks. If app name equal to window_class parameter, return title of this app.
# Ex. -> get_window.py — ~/Desktop/projects — Atom
for active_id in active_windows_ids:
window = subprocess.Popen(["xprop",
"-id",
active_id.strip(),
"WM_CLASS",
"_NET_WM_NAME"],
stdout=subprocess.PIPE).communicate()
window = window[0].decode("utf-8").split('"')
if window_class == window[3].lower():
return window[5]


Mainloop



def run(self):
song = self.title_of_window(self.SPOTIFY)
if self.temp_song_name != song:
lyric = self.get_lyric(song)
self.add_lyric_to_tk(song,lyric)
else:
self.add_lyric_to_tk(song, "Not Found")
self.top.after(5000,self.run)
self.top.mainloop()


Error:



File "spotifyLyric.py", line 137, in run
song = self.title_of_window(self.SPOTIFY)
File "spotifyLyric.py", line 51, in title_of_window
stdout=subprocess.PIPE).communicate()
RecursionError: maximum recursion depth exceeded while calling a Python object









share|improve this question


























    up vote
    0
    down vote

    favorite












    I am trying to current playing track name from Spotify desktop app window title by using subprocess. In generally, my code is working. But when trying to retrieve song name each five second, i get RecursionError. Where is the problem?



    Code1



    def title_of_window(self,window_class):
    """
    Retrieves the title of application by through 'subprocess'.

    Params:
    window_class (string) -- name of the application to be taken the title
    ex. --> spotify
    --> filezilla
    --> putty
    --> atom

    For this app:
    - window_class parameter must be equal to "spotify"
    - Retrieves the current playing song name from Spotify.

    """
    # Finds id of all GUI apps who running.
    # Ex. -> ['0x200000a', '0x3800007', '0x4800001', '0x2e00010', '0x3600001n']
    active_windows = subprocess.Popen(["xprop",
    "-root",
    "_NET_CLIENT_LIST_STACKING"],
    stdout=subprocess.PIPE).communicate()
    active_windows_ids = active_windows[0].decode("utf-8").split("# ")[1].split(", ")
    #
    # Sends all ids to 'xprop -id' and checks. If app name equal to window_class parameter, return title of this app.
    # Ex. -> get_window.py — ~/Desktop/projects — Atom
    for active_id in active_windows_ids:
    window = subprocess.Popen(["xprop",
    "-id",
    active_id.strip(),
    "WM_CLASS",
    "_NET_WM_NAME"],
    stdout=subprocess.PIPE).communicate()
    window = window[0].decode("utf-8").split('"')
    if window_class == window[3].lower():
    return window[5]


    Mainloop



    def run(self):
    song = self.title_of_window(self.SPOTIFY)
    if self.temp_song_name != song:
    lyric = self.get_lyric(song)
    self.add_lyric_to_tk(song,lyric)
    else:
    self.add_lyric_to_tk(song, "Not Found")
    self.top.after(5000,self.run)
    self.top.mainloop()


    Error:



    File "spotifyLyric.py", line 137, in run
    song = self.title_of_window(self.SPOTIFY)
    File "spotifyLyric.py", line 51, in title_of_window
    stdout=subprocess.PIPE).communicate()
    RecursionError: maximum recursion depth exceeded while calling a Python object









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to current playing track name from Spotify desktop app window title by using subprocess. In generally, my code is working. But when trying to retrieve song name each five second, i get RecursionError. Where is the problem?



      Code1



      def title_of_window(self,window_class):
      """
      Retrieves the title of application by through 'subprocess'.

      Params:
      window_class (string) -- name of the application to be taken the title
      ex. --> spotify
      --> filezilla
      --> putty
      --> atom

      For this app:
      - window_class parameter must be equal to "spotify"
      - Retrieves the current playing song name from Spotify.

      """
      # Finds id of all GUI apps who running.
      # Ex. -> ['0x200000a', '0x3800007', '0x4800001', '0x2e00010', '0x3600001n']
      active_windows = subprocess.Popen(["xprop",
      "-root",
      "_NET_CLIENT_LIST_STACKING"],
      stdout=subprocess.PIPE).communicate()
      active_windows_ids = active_windows[0].decode("utf-8").split("# ")[1].split(", ")
      #
      # Sends all ids to 'xprop -id' and checks. If app name equal to window_class parameter, return title of this app.
      # Ex. -> get_window.py — ~/Desktop/projects — Atom
      for active_id in active_windows_ids:
      window = subprocess.Popen(["xprop",
      "-id",
      active_id.strip(),
      "WM_CLASS",
      "_NET_WM_NAME"],
      stdout=subprocess.PIPE).communicate()
      window = window[0].decode("utf-8").split('"')
      if window_class == window[3].lower():
      return window[5]


      Mainloop



      def run(self):
      song = self.title_of_window(self.SPOTIFY)
      if self.temp_song_name != song:
      lyric = self.get_lyric(song)
      self.add_lyric_to_tk(song,lyric)
      else:
      self.add_lyric_to_tk(song, "Not Found")
      self.top.after(5000,self.run)
      self.top.mainloop()


      Error:



      File "spotifyLyric.py", line 137, in run
      song = self.title_of_window(self.SPOTIFY)
      File "spotifyLyric.py", line 51, in title_of_window
      stdout=subprocess.PIPE).communicate()
      RecursionError: maximum recursion depth exceeded while calling a Python object









      share|improve this question













      I am trying to current playing track name from Spotify desktop app window title by using subprocess. In generally, my code is working. But when trying to retrieve song name each five second, i get RecursionError. Where is the problem?



      Code1



      def title_of_window(self,window_class):
      """
      Retrieves the title of application by through 'subprocess'.

      Params:
      window_class (string) -- name of the application to be taken the title
      ex. --> spotify
      --> filezilla
      --> putty
      --> atom

      For this app:
      - window_class parameter must be equal to "spotify"
      - Retrieves the current playing song name from Spotify.

      """
      # Finds id of all GUI apps who running.
      # Ex. -> ['0x200000a', '0x3800007', '0x4800001', '0x2e00010', '0x3600001n']
      active_windows = subprocess.Popen(["xprop",
      "-root",
      "_NET_CLIENT_LIST_STACKING"],
      stdout=subprocess.PIPE).communicate()
      active_windows_ids = active_windows[0].decode("utf-8").split("# ")[1].split(", ")
      #
      # Sends all ids to 'xprop -id' and checks. If app name equal to window_class parameter, return title of this app.
      # Ex. -> get_window.py — ~/Desktop/projects — Atom
      for active_id in active_windows_ids:
      window = subprocess.Popen(["xprop",
      "-id",
      active_id.strip(),
      "WM_CLASS",
      "_NET_WM_NAME"],
      stdout=subprocess.PIPE).communicate()
      window = window[0].decode("utf-8").split('"')
      if window_class == window[3].lower():
      return window[5]


      Mainloop



      def run(self):
      song = self.title_of_window(self.SPOTIFY)
      if self.temp_song_name != song:
      lyric = self.get_lyric(song)
      self.add_lyric_to_tk(song,lyric)
      else:
      self.add_lyric_to_tk(song, "Not Found")
      self.top.after(5000,self.run)
      self.top.mainloop()


      Error:



      File "spotifyLyric.py", line 137, in run
      song = self.title_of_window(self.SPOTIFY)
      File "spotifyLyric.py", line 51, in title_of_window
      stdout=subprocess.PIPE).communicate()
      RecursionError: maximum recursion depth exceeded while calling a Python object






      python recursion subprocess






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Batuhan Gürses

      34




      34
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          The problem is that you're calling self.top.mainloop() multiple times. You should be able to fix the error by moving the call to self.top.mainloop() into your __init__() method.



          def __init__(self):
          ...
          self.run()
          self.top.mainloop()

          def run(self):
          song = self.title_of_window(self.SPOTIFY)
          if self.temp_song_name != song:
          lyric = self.get_lyric(song)
          self.add_lyric_to_tk(song,lyric)
          else:
          self.add_lyric_to_tk(song, "Not Found")
          self.top.after(5000,self.run)


          Does this solve your problem?



          EDIT: see here for a longer description of the problem.






          share|improve this answer





















          • Yes, solved!! I understand what my problem is. Thank you so much...
            – Batuhan Gürses
            2 days ago










          • You're welcome! Glad that I could help
            – Felix
            2 days ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350344%2fsubprocess-maximum-recursion-depth-exceeded%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          The problem is that you're calling self.top.mainloop() multiple times. You should be able to fix the error by moving the call to self.top.mainloop() into your __init__() method.



          def __init__(self):
          ...
          self.run()
          self.top.mainloop()

          def run(self):
          song = self.title_of_window(self.SPOTIFY)
          if self.temp_song_name != song:
          lyric = self.get_lyric(song)
          self.add_lyric_to_tk(song,lyric)
          else:
          self.add_lyric_to_tk(song, "Not Found")
          self.top.after(5000,self.run)


          Does this solve your problem?



          EDIT: see here for a longer description of the problem.






          share|improve this answer





















          • Yes, solved!! I understand what my problem is. Thank you so much...
            – Batuhan Gürses
            2 days ago










          • You're welcome! Glad that I could help
            – Felix
            2 days ago















          up vote
          0
          down vote



          accepted










          The problem is that you're calling self.top.mainloop() multiple times. You should be able to fix the error by moving the call to self.top.mainloop() into your __init__() method.



          def __init__(self):
          ...
          self.run()
          self.top.mainloop()

          def run(self):
          song = self.title_of_window(self.SPOTIFY)
          if self.temp_song_name != song:
          lyric = self.get_lyric(song)
          self.add_lyric_to_tk(song,lyric)
          else:
          self.add_lyric_to_tk(song, "Not Found")
          self.top.after(5000,self.run)


          Does this solve your problem?



          EDIT: see here for a longer description of the problem.






          share|improve this answer





















          • Yes, solved!! I understand what my problem is. Thank you so much...
            – Batuhan Gürses
            2 days ago










          • You're welcome! Glad that I could help
            – Felix
            2 days ago













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The problem is that you're calling self.top.mainloop() multiple times. You should be able to fix the error by moving the call to self.top.mainloop() into your __init__() method.



          def __init__(self):
          ...
          self.run()
          self.top.mainloop()

          def run(self):
          song = self.title_of_window(self.SPOTIFY)
          if self.temp_song_name != song:
          lyric = self.get_lyric(song)
          self.add_lyric_to_tk(song,lyric)
          else:
          self.add_lyric_to_tk(song, "Not Found")
          self.top.after(5000,self.run)


          Does this solve your problem?



          EDIT: see here for a longer description of the problem.






          share|improve this answer












          The problem is that you're calling self.top.mainloop() multiple times. You should be able to fix the error by moving the call to self.top.mainloop() into your __init__() method.



          def __init__(self):
          ...
          self.run()
          self.top.mainloop()

          def run(self):
          song = self.title_of_window(self.SPOTIFY)
          if self.temp_song_name != song:
          lyric = self.get_lyric(song)
          self.add_lyric_to_tk(song,lyric)
          else:
          self.add_lyric_to_tk(song, "Not Found")
          self.top.after(5000,self.run)


          Does this solve your problem?



          EDIT: see here for a longer description of the problem.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          Felix

          2,1392826




          2,1392826












          • Yes, solved!! I understand what my problem is. Thank you so much...
            – Batuhan Gürses
            2 days ago










          • You're welcome! Glad that I could help
            – Felix
            2 days ago


















          • Yes, solved!! I understand what my problem is. Thank you so much...
            – Batuhan Gürses
            2 days ago










          • You're welcome! Glad that I could help
            – Felix
            2 days ago
















          Yes, solved!! I understand what my problem is. Thank you so much...
          – Batuhan Gürses
          2 days ago




          Yes, solved!! I understand what my problem is. Thank you so much...
          – Batuhan Gürses
          2 days ago












          You're welcome! Glad that I could help
          – Felix
          2 days ago




          You're welcome! Glad that I could help
          – Felix
          2 days ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350344%2fsubprocess-maximum-recursion-depth-exceeded%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin