1

I'm using an updating script and trying to get it to work with cython. It seems the pyupdater script is ignored (no print and not updating). It works fine with standard python, but calling a pyx file it seems it skips over this so no print and update.

If python main.py (Calls a cython script there is no print and to a larger extent it does not update).

def main():
    import collections
    import os
    import sys
    import time
    import bb.bb_module

    import progressbar
    import urllib3.poolmanager
    from pyupdater.client import Client, AppUpdate
    from selenium import webdriver
    from selenium.common.exceptions import TimeoutException
    from selenium.webdriver.chrome.options import Options

    from client_config import ClientConfig


if __name__ == '__main__':
    main()

Cython pyx file:

import urllib3.poolmanager

orig_urlopen = urllib3.poolmanager.PoolManager.urlopen


def new_urlopen(self, method, url, redirect=True, **kw):
    if "s3.amazonaws.com" in url and 'authorization' in self.headers:
        self.headers.pop('authorization')
    return orig_urlopen(self, method, url, redirect, **kw)

import sys
urllib3.poolmanager.PoolManager.urlopen = new_urlopen

import logging


import http.client as http_client



import logging
from selenium import webdriver



from client_config import ClientConfig
from pyupdater.client import Client, AppUpdate

import progressbar
import sys

bar = None
import sys
import os
import sys
def check_for_update():
    stdout_save = sys.stdout              
    sys.stdout = open(os.devnull, 'w')   

    def cb(status):
        global bar
        from tqdm import tqdm
        if bar is None:
            bar = progressbar.ProgressBar(widgets = [progressbar.Percentage(), progressbar.Bar(), progressbar.FileTransferSpeed(), ' ', progressbar.ETA()
               ], fd=sys.stdout).start()
        zz = float(status['percent_complete'])

        bar.update(zz) 



    stdout_save = sys.stdout
    sys.stdout = open(os.devnull, 'w')
    client = Client(ClientConfig(), refresh=True,
                    headers={'basic_auth': 'brofewfefwefewef:Er8qUc9c48LHAtH5mGz5'})
    sys.stdout = stdout_save
    client.platform = "win"
    app_update = client.update_check(ClientConfig.APP_NAME, ClientConfig.APP_VERSION, channel='stable')
    if app_update is not None:
        app_update.progress_hooks.append(cb)
        if app_update.download():
            if isinstance(app_update, AppUpdate):
                app_update.extract_restart()
                return True
            else:
                app_update.extract()
                return True
    return False


def main():
    import sys
    class DevNull:
       def write(self, msg):
            pass

    print('Current version is ', ClientConfig.APP_VERSION)

    if check_for_update():
        pass
    else:
        pass


    import os

    from contextlib import contextmanager
    import sys, os

    driver = webdriver.Firefox()
if __name__ == "__main__":
    main()



driver = webdriver.Chrome()
sys.stdout = sys.__stdout__
print('This will not print anything')

Output:

DevTools listening on ws://127.0.0.1:12284/devtools/browser/b2f98849-8daa-4442-b594-6e7a904c2091
This will not print anything

It looks as if pyupdater is being ignored when calling cython script. It does not print or update.

I've created a repo to reproduce these issues. How can I get it to update when using cython? I have also included a working pythonic version to see the difference if needed

I suspect:

if __name__ == "__main__":
    main()

used in the cython script may be the issue as other than pyupdater the cython script runs perfectly.

  • You should authorize it once first, as told by the message. – Raptor Jan 10 '18 at 01:40
  • Just use your browser to go here: https://bitbucket.org/site/oauth2/authorize?response_type=code&client_id=&state=WDWADWADWADWADWDA and follow instructions. – Raptor Jan 10 '18 at 01:51
  • App passwords fixed this though... cythonising seems to be causing issues –  Jan 27 '18 at 09:03
  • I _think_ this is a duplicate of https://stackoverflow.com/questions/8295555/how-to-reload-a-python3-c-extension-module. I'm really struggling to understand the question though. – DavidW Jan 27 '18 at 10:07
  • @DavidW I don't really get why this works with a python script, but yet when I call an identical script through pyx file the whole script works save for the pyupdater part. –  Jan 27 '18 at 10:11
  • Because Python lets you reload scripts that have already been imported, but does not let you reload extension modules. – DavidW Jan 27 '18 at 10:22
  • @DavidW Could you provide a working example at all? –  Jan 27 '18 at 12:03
  • @user9099, try to comment all the override of `sys.stdout` to see if there's a clue in the messages. You should also log each step and assert the expected output. – Florent B. Jan 27 '18 at 13:19
  • @FlorentB. I've added debug in my repo and it is not of any help. It's like it just skips over it. I find it strange how the script runs except for pyupdater. Puzzling.. –  Jan 28 '18 at 03:17

0 Answers0