Flexx for Python: how to get PyComponent instance outside of the app context (watchdog EventHandler)2019 Community Moderator ElectionHow do I copy a file in Python?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?Getting the class name of an instance?Getting the last element of a list in PythonHow to get the number of elements in a list in Python?How to concatenate two lists in Python?How to use threading in Python?How to lowercase a string in Python?
Replacing Windows 7 security updates with anti-virus?
PTIJ: Why can't I eat anything?
Why the color red for the Republican Party
How strictly should I take "Candidates must be local"?
Peter's Strange Word
infinitive telling the purpose
How much attack damage does the AC boost from a shield prevent on average?
What to do when during a meeting client people start to fight (even physically) with each others?
They call me Inspector Morse
Low budget alien movie about the Earth being cooked
Why does the negative sign arise in this thermodynamic relation?
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Are babies of evil humanoid species inherently evil?
Good allowance savings plan?
Word for a person who has no opinion about whether god exists
Are the terms "stab" and "staccato" synonyms?
The bar has been raised
A three room house but a three headED dog
Unreachable code, but reachable with exception
Accountant/ lawyer will not return my call
Rejected in 4th interview round citing insufficient years of experience
Is there an equal sign with wider gap?
Should I tell my boss the work he did was worthless
PTIJ: How can I halachically kill a vampire?
Flexx for Python: how to get PyComponent instance outside of the app context (watchdog EventHandler)
2019 Community Moderator ElectionHow do I copy a file in Python?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?Getting the class name of an instance?Getting the last element of a list in PythonHow to get the number of elements in a list in Python?How to concatenate two lists in Python?How to use threading in Python?How to lowercase a string in Python?
I'm currently diving into Flexx for making a UI to my Python program. I'm starting to get the hang of it but I'm running into a problem.
I need to be able to call a PyComponent
's method from outside the scope of the App
. I understand that app.cls
gives the class that was used to instanciate the App, but it's not the actual instance, so I can't do something like app.cls.my_method(...)
.
Is there a way to get the instance of the component inside the app wrapper, only knowing the App
instance?
Thanks!
EDIT: After looking at the source, I found the mostly undocumented AppManager
and Session
definitions and could get a reference to the component's instance with:
from flexx.app import manager
app_instance = manager.get_connections('MyAppName')[0].app
But if I call one of its methods from a watchdog.events.FileSystemEventHandler
instantiated by the watchdog
library, I get the following traceback:
File "myfile.py", line 37, in on_created
manager.get_connections('MyAppName')[0].app.update_verbose(False)
File "libsite-packagesflexxevent_action.py", line 150, in __call__
if loop.can_mutate(ob):
File "libsite-packagesflexxevent_loop.py", line 85, in can_mutate
active = self.get_active_component()
File "libsite-packagesflexxevent_loop.py", line 103, in get_active_component
if len(self._local._active_components) > 0:
AttributeError: '_thread._local' object has no attribute '_active_components'
Note that update_verbose
is a Flexx action that mutates a property. I suspect an issue where the watchdog handler is running on a different thread but I can't see what to change...
python multithreading python-multithreading python-watchdog
add a comment |
I'm currently diving into Flexx for making a UI to my Python program. I'm starting to get the hang of it but I'm running into a problem.
I need to be able to call a PyComponent
's method from outside the scope of the App
. I understand that app.cls
gives the class that was used to instanciate the App, but it's not the actual instance, so I can't do something like app.cls.my_method(...)
.
Is there a way to get the instance of the component inside the app wrapper, only knowing the App
instance?
Thanks!
EDIT: After looking at the source, I found the mostly undocumented AppManager
and Session
definitions and could get a reference to the component's instance with:
from flexx.app import manager
app_instance = manager.get_connections('MyAppName')[0].app
But if I call one of its methods from a watchdog.events.FileSystemEventHandler
instantiated by the watchdog
library, I get the following traceback:
File "myfile.py", line 37, in on_created
manager.get_connections('MyAppName')[0].app.update_verbose(False)
File "libsite-packagesflexxevent_action.py", line 150, in __call__
if loop.can_mutate(ob):
File "libsite-packagesflexxevent_loop.py", line 85, in can_mutate
active = self.get_active_component()
File "libsite-packagesflexxevent_loop.py", line 103, in get_active_component
if len(self._local._active_components) > 0:
AttributeError: '_thread._local' object has no attribute '_active_components'
Note that update_verbose
is a Flexx action that mutates a property. I suspect an issue where the watchdog handler is running on a different thread but I can't see what to change...
python multithreading python-multithreading python-watchdog
add a comment |
I'm currently diving into Flexx for making a UI to my Python program. I'm starting to get the hang of it but I'm running into a problem.
I need to be able to call a PyComponent
's method from outside the scope of the App
. I understand that app.cls
gives the class that was used to instanciate the App, but it's not the actual instance, so I can't do something like app.cls.my_method(...)
.
Is there a way to get the instance of the component inside the app wrapper, only knowing the App
instance?
Thanks!
EDIT: After looking at the source, I found the mostly undocumented AppManager
and Session
definitions and could get a reference to the component's instance with:
from flexx.app import manager
app_instance = manager.get_connections('MyAppName')[0].app
But if I call one of its methods from a watchdog.events.FileSystemEventHandler
instantiated by the watchdog
library, I get the following traceback:
File "myfile.py", line 37, in on_created
manager.get_connections('MyAppName')[0].app.update_verbose(False)
File "libsite-packagesflexxevent_action.py", line 150, in __call__
if loop.can_mutate(ob):
File "libsite-packagesflexxevent_loop.py", line 85, in can_mutate
active = self.get_active_component()
File "libsite-packagesflexxevent_loop.py", line 103, in get_active_component
if len(self._local._active_components) > 0:
AttributeError: '_thread._local' object has no attribute '_active_components'
Note that update_verbose
is a Flexx action that mutates a property. I suspect an issue where the watchdog handler is running on a different thread but I can't see what to change...
python multithreading python-multithreading python-watchdog
I'm currently diving into Flexx for making a UI to my Python program. I'm starting to get the hang of it but I'm running into a problem.
I need to be able to call a PyComponent
's method from outside the scope of the App
. I understand that app.cls
gives the class that was used to instanciate the App, but it's not the actual instance, so I can't do something like app.cls.my_method(...)
.
Is there a way to get the instance of the component inside the app wrapper, only knowing the App
instance?
Thanks!
EDIT: After looking at the source, I found the mostly undocumented AppManager
and Session
definitions and could get a reference to the component's instance with:
from flexx.app import manager
app_instance = manager.get_connections('MyAppName')[0].app
But if I call one of its methods from a watchdog.events.FileSystemEventHandler
instantiated by the watchdog
library, I get the following traceback:
File "myfile.py", line 37, in on_created
manager.get_connections('MyAppName')[0].app.update_verbose(False)
File "libsite-packagesflexxevent_action.py", line 150, in __call__
if loop.can_mutate(ob):
File "libsite-packagesflexxevent_loop.py", line 85, in can_mutate
active = self.get_active_component()
File "libsite-packagesflexxevent_loop.py", line 103, in get_active_component
if len(self._local._active_components) > 0:
AttributeError: '_thread._local' object has no attribute '_active_components'
Note that update_verbose
is a Flexx action that mutates a property. I suspect an issue where the watchdog handler is running on a different thread but I can't see what to change...
python multithreading python-multithreading python-watchdog
python multithreading python-multithreading python-watchdog
edited Mar 7 at 12:48
beeb
asked Mar 6 at 16:27
beebbeeb
641526
641526
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As suspected, the problem probably comes from the fact that the FileSystemEventHandler
is running on a different thread than the Flexx loop. Thanks to the author almarklein for his help on solving this.
The solution was to get a reference to the root object, not with the complicated method described above in my question, but rather with the return value from the launch
call:
root = app.launch('app')
Then inside the event handler, tell the main loop to call my method (decorated with @flx.action
):
flx.loop.call_soon(root.my_action, 'argument`)
Hope this helps someone some day!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027872%2fflexx-for-python-how-to-get-pycomponent-instance-outside-of-the-app-context-wa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As suspected, the problem probably comes from the fact that the FileSystemEventHandler
is running on a different thread than the Flexx loop. Thanks to the author almarklein for his help on solving this.
The solution was to get a reference to the root object, not with the complicated method described above in my question, but rather with the return value from the launch
call:
root = app.launch('app')
Then inside the event handler, tell the main loop to call my method (decorated with @flx.action
):
flx.loop.call_soon(root.my_action, 'argument`)
Hope this helps someone some day!
add a comment |
As suspected, the problem probably comes from the fact that the FileSystemEventHandler
is running on a different thread than the Flexx loop. Thanks to the author almarklein for his help on solving this.
The solution was to get a reference to the root object, not with the complicated method described above in my question, but rather with the return value from the launch
call:
root = app.launch('app')
Then inside the event handler, tell the main loop to call my method (decorated with @flx.action
):
flx.loop.call_soon(root.my_action, 'argument`)
Hope this helps someone some day!
add a comment |
As suspected, the problem probably comes from the fact that the FileSystemEventHandler
is running on a different thread than the Flexx loop. Thanks to the author almarklein for his help on solving this.
The solution was to get a reference to the root object, not with the complicated method described above in my question, but rather with the return value from the launch
call:
root = app.launch('app')
Then inside the event handler, tell the main loop to call my method (decorated with @flx.action
):
flx.loop.call_soon(root.my_action, 'argument`)
Hope this helps someone some day!
As suspected, the problem probably comes from the fact that the FileSystemEventHandler
is running on a different thread than the Flexx loop. Thanks to the author almarklein for his help on solving this.
The solution was to get a reference to the root object, not with the complicated method described above in my question, but rather with the return value from the launch
call:
root = app.launch('app')
Then inside the event handler, tell the main loop to call my method (decorated with @flx.action
):
flx.loop.call_soon(root.my_action, 'argument`)
Hope this helps someone some day!
edited Mar 7 at 14:29
answered Mar 7 at 14:13
beebbeeb
641526
641526
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55027872%2fflexx-for-python-how-to-get-pycomponent-instance-outside-of-the-app-context-wa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown