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.