Cythonised应用程序不更新

时间:2018-01-10 01:34:19

标签: python selenium cython updates pyinstaller

我正在使用更新脚本并试图让它与cython一起使用。似乎忽略了pyupdater脚本(没有打印而没有更新)。它使用标准的python工作正常,但调用pyx文件似乎它跳过这个没有打印和更新。

如果python main.py(调用cython脚本没有打印,并且在更大程度上它不会更新)。

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文件:

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')

输出:

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

在调用cython脚本时,好像忽略了pyupdater。它不会打印或更新。

我已经为reproduce这些问题创建了一个回购。如何在使用cython时更新它?我还包括一个工作pythonic version,以便在需要时看到差异

我怀疑:

if __name__ == "__main__":
    main()
在cython脚本中使用的

可能是pythondater以外的问题,cython脚本运行得很好。

0 个答案:

没有答案