Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2429 - Update button compat with NETCORE #2432

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

jmcouffin
Copy link
Contributor

fix #2429

@jmcouffin jmcouffin added Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] pyRevit 5 pyRevit 5 coming release labels Oct 24, 2024
@dosymep
Copy link
Member

dosymep commented Oct 24, 2024

@jmcouffin maybe try to use Ping?

@jmcouffin
Copy link
Contributor Author

@jmcouffin maybe try to use Ping?

I will have a look eventually,
I am a bit swamped with work right now.

@sanzoghenzo
Copy link
Contributor

sanzoghenzo commented Oct 24, 2024

Do we really need to check the connection before doing anything? It makes sense if we don't want to crash the code with timeout exceptions... anyway:

  • can_access_url is only used by check_internet_connection;
  • check_internet_connection uses (not-so-)random urls that have nothing to do with the update process (well, only github.com does), and returns the first successful url, but nobody cares about it
  • check_internet_connection is only used by versionmgr.updater._check_connection that actually "cares" about that url, just to display a debug message and return True

This SO answer suggests using socket and a fixed ip address and tcp port instead of relying on name resolutions and application layers.
Here's the code, that I would put in the _check_connection function and discard the other two functions
Not sure if it plays well with IronPython/python.net, though...

import socket

def _check_connection(host="8.8.8.8", port=53, timeout=3):
    """
    Host: 8.8.8.8 (google-public-dns-a.google.com)
    OpenPort: 53/tcp
    Service: domain (DNS/TCP)
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except socket.error as ex:
        print(ex)  # change it with some logging
        return False

Obviously the .net Ping solution could be the best solution, so that we can port the core of pyrevit to .NET more easily 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] pyRevit 5 pyRevit 5 coming release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants