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

Guy only allows you to run one instance of your app at a time #13

Closed
alnumac opened this issue Apr 8, 2020 · 9 comments
Closed

Guy only allows you to run one instance of your app at a time #13

alnumac opened this issue Apr 8, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@alnumac
Copy link

alnumac commented Apr 8, 2020

Windows using chrome.
Guy launches chrome, but stops its process right after. Chrome stays open.

One way to fix the issue is to change line 474.
% os.path.join(tempfile.gettempdir(), ".guyapp_"+re.sub(r"[^a-zA-Z]","_",url))
to
% os.path.join(tempfile.gettempdir(), ".guyapp_"+re.sub(r"[^a-zA-Z0-9]","_",url))

This includes the port number in the cache folder name. Since each Chrome instance is now using its own cache folder, Guy can now run multiple instances.

I also recommend adding :
args.append("--aggressive-cache-discard")

Basically, since it is running locally, the cache is just causing issues during dev.

@manatlan manatlan added the enhancement New feature or request label Apr 9, 2020
@manatlan
Copy link
Owner

manatlan commented Apr 9, 2020

hi,

This includes the port number in the cache folder name

It's the old behavior in oldest versions of guy. But I have experienced issues with that : when launching multiple versions of one (freezed) app. They didn't share the same cache (and things stored in client/localStorage were lost (not shared)).
So I decided to remove the port number in cache folder name. But you're right : it could cause trouble on windows platforms. Sometimes it works (you can run multiple instance), sometimes it won't work. I can't figure how to make it works each time (but it's not the same behaviour when app are freezed or not).
Perhaps your tips (--aggressive-cache-discard) is the solution ?!

Perhaps, the solution is to use the config file to store common things, and to avoid to use client/localStorage for that ...

But sure, I need to dig on that !

@alnumac
Copy link
Author

alnumac commented Apr 9, 2020

I think I know what's going on. Chrome only supports one process per user directory. So the subprocess.wait() cannot work. Which explains why multiple directories fixed the issue.

I wonder how we could detect if an instance of the current program is running chrome. If it is, reuse the Chrome process. Now, the issue would be that it wouldn't close any instance of that program until all windows are closed, but it is (maybe) better than not being able to start seperate instances.

I'll try to implement this

@manatlan
Copy link
Owner

manatlan commented Apr 9, 2020

If you reach to do that ... it could be marvelous ;-) ... but I'm afraid it could be make guy more complex than the current one ;-)

I've got a lot of old guy's app (freezed, on wins platforms, for my teamates at my job), which store a lot of things in the localStorage. And this issue is really annoying for me ;-)

@manatlan manatlan pinned this issue Apr 9, 2020
@manatlan
Copy link
Owner

manatlan commented Apr 10, 2020

thinking mode ...

Perhaps, the simplest solution should be : to disallow to run a second instance of the same app.
by preventing the user "your app is already running", or better set the focus to the running instance.

it makes sense

@manatlan
Copy link
Owner

or better ...

Let the user choose the behavior. Default, is to run multiple instance ... but by providing a switch, it could disallow multiple instance.

By the way, there is a big flaw ... on *nix platforms, the temp chrome cache folder is created in /tmp (so after a reboot ... you loose all). On windows : nothing is loosed (the temp dir is not flushed after reboot).

I should state on that flaw. too !
I like the idea to be able to store things in localstorage ...(perhaps another switch to allow/disallow this kind of feature?!)

@manatlan
Copy link
Owner

manatlan commented Apr 10, 2020

there are works on thats questions ;-).
And the "cef mode" should inherits of the same things. No trouble for "Server mode"

@manatlan
Copy link
Owner

manatlan commented Apr 11, 2020

I've reached to make something !

If "mono instance", it can't run a second instance : and so the app can use its localStorage, to store/retrieve things
If "multi instance" : each app got its separate cache(localStorage) ! (in this cases : you should use the "config" system to store common things)

I've got a lot of test, and ensure the same behaviour for "cef mode" ... it will be for a 0.6 release !

I like this behaviour, because it doesn't break all

@manatlan
Copy link
Owner

Here is a preversion of the futur 0.6 : https://github.com/manatlan/guy/tree/futur

@manatlan manatlan unpinned this issue Apr 14, 2020
@manatlan
Copy link
Owner

The problem is resolved ;-)
The 0.6 is here (git+pypi)

if you want to be able to run only one instance ...

    app.run(one=True) # or runCef

in this case, you will be able to use localStorage to store/reuse things
and the app will refocus if you try to launch a second instance (but cef/linux can't refocus!)

If you want to run multiple instances (the default mode)

    app.run() # or runCef

in this case, don't count on localstorage (the chrome cache is created/deleted each time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants