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

Ensure that pipe works #234

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pypresence/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import tempfile
import time
import warnings

from .exceptions import PyPresenceException

Expand All @@ -20,6 +21,15 @@ def remove_none(d: dict):
del d[item]
return d

def test_ipc_path(path):
'''Tests an IPC pipe to ensure that it actually works'''
try:
with open(path) as f:
return True
except Exception as e:
warnings.warn(f"IPC pipe path {path.path} exists, but could not be opened because of {e}. Trying next pipe")
return False


# Returns on first IPC pipe matching Discord's
def get_ipc_path(pipe=None):
Expand All @@ -40,7 +50,7 @@ def get_ipc_path(pipe=None):
full_path = os.path.abspath(os.path.join(tempdir, path))
if sys.platform == 'win32' or os.path.isdir(full_path):
for entry in os.scandir(full_path):
if entry.name.startswith(ipc) and os.path.exists(entry):
if entry.name.startswith(ipc) and os.path.exists(entry) and test_ipc_path(entry):
return entry.path


Expand Down
Loading