manatlan / guy

Graphics User Ynterface : a simple module for making GUI applications (with html/js) for py3 ... to target windows, linux, mac & android
Apache License 2.0
202 stars 23 forks source link

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

Closed alnumac closed 4 years ago

alnumac commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

manatlan commented 4 years ago

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 commented 4 years ago

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

manatlan commented 4 years ago

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)