using Threads with Jython/wlst - multithreading

I'm working with weblogic servers and want a class to handle every connection separately with a handler in my scripts.
I'm using jython2.7 as interpreter and include all the weblogic libs need.
The Idea is to have a handler for every conncetion to the adminserver I have and controll them separately.
For this I wrote a class with the functions needed ( shutdown, getServers, etc ). The functions are working. My problem is the script only has the last connection established activ and not the connection in my class itself.
I thougt Processes would be the thing, and made something like this.
p1 = Process( target = IDIHandler.connect, args = None )
p2 = Process( target = IDEHandler.connect, args = None )
but it doesn't seem to work... The Process starts right away and not if I'm using p1.start() plus the same problem like above. only the last connected server is connceted.
I have to admit I'm not even sure if Process is the correct way for my Problem. If you have other options for me to try I'll do :)
Thanks in advance

Related

How to use pystemd to control systemd timedated ntp service?

I'm working on a python app that needs to get the NTPSynchronized parameter from system-timedated. I'd also like to be able to start and stop the NTP service by using the SetNTP method.
To communicate with timedated over d-bus I have been using this as reference: https://www.freedesktop.org/wiki/Software/systemd/timedated/
I previously got this working with dbus-python, but have since learned that this library has been deprecated. I tried the dbus_next package, but that does not have support for Python 3.5, which I need.
I came across the pystemd package, but I am unsure if this can be used to do what I want. The only documentation I have been able to find is this example (https://github.com/facebookincubator/pystemd), but I can not figure out how to use this to work with system-timedated.
Here is the code I have that works with dbus-python:
import dbus
BUS_NAME = 'org.freedesktop.timedate1`
IFACE = 'org.freedesktop.timedate1`
bus = dbus.SystemBus()
timedate_obj = bus.get_object(BUS_NAME, '/org/freedesktop/timedate1')
# Get synchronization value
is_sync = timedate_obj.Get(BUS_NAME, 'NTPSynchronized', dbus_interface=dbus.PROPERTIES_IFACE)
# Turn off NTP
timedate_obj.SetNTP(False,False, dbus_interface=IFACE)
Here's what I have so far with pystemd, but I don't think I'm accessing it in the right way:
from pystemd.systemd1 import Unit
unit = Unit(b'systemd-timesyncd.service')
unit.load()
# Try to access properties
prop = unit.Properties
prop.NTPSynchronized
Running that I get:
Attribute Error: 'SDInterface' object has no attribute 'NTPSynchronized'
I have a feeling that either the service I entered is wrong, or the way I'm accessing properties is wrong, or even both are wrong.
Any help or advice is appreciated.
Looking at the source code, it appears that using the pystemd.systemd1 Unit object has a default destination of "org.freedesktop.systemd1" + the service name (https://github.com/facebookincubator/pystemd/blob/master/pystemd/systemd1/unit.py)
This is not what I want because I am trying to access "org.freedesktop.timedate1"
So instead I instantiated it's base class SDObject from pystemd.base (https://github.com/facebookincubator/pystemd/blob/master/pystemd/base.py)
The following code allowed me to get the sync status of NTP
from pystemd.base import SDObject
obj = SDObject(
destination=b'org.freedesktop.timedate1',
path=b'/org/freedesktop/timedate1',
bus=None,
_autoload=False
)
obj.load()
is_sync = obj.Properties.Get('org.freedesktop.timedate1','NTPSynchronized')
print(is_sync)
Not sure if this is what the library author intended, but hey it works!

Close cefpython clientand restart a new one

During the application flow I would like to close cefpython running client and open a new one; I've this function
....
while True:
settings = {...}
settings2= {...}
cef.Initialize(settings=settings)
self.BROWSER = cef.CreateBrowserSync(url=url,
window_title="Tutorial",
browserSettings=settings2)
bindings = cef.JavascriptBindings(bindToFrames=False,
bindToPopups=False)
bindings.SetFunction("backend", func)
self.BROWSER.SetJavascriptBindings(bindings)
cef.MessageLoop()
cef.Shutdown()
and in another function I have this call
self.BROWSER.CloseBrowser(True)
Browser start on first run and is closed but it does not restart. If I comment the line
...
cef.MessageLoop()
#cef.Shutdown()
in the first function the browser does restart but it get stuck and I can't use it.
Thanks in advance.
Functions like cef.Initialize and cef.Shutdown can be called only once during app lifetime. You also shouldn't call cef.MessageLoop multiple times. Your code while True doesn't make much sense, because you do not give browsers time to initialize and load. You should use events like LoadHandler.OnLoadEnd or OnLoadingStateChange or others depending on what you're trying to accomplish.

webdriver-sync running asynchronously?

I'm trying to create selenium tests that run each step synchronously, without using .then(), or async/await. The reason for this is that I want to create a set of functions that allow pretty much anyone on our test team, almost regardless of tech skills to write easy to read automated tests. It looks to me like webdriver-sync should give me exactly what I want. However, the following dummy code is producing problems:
var wd = require('webdriver-sync');
var By = wd.By;
var Chromedriver = wd.Chromedriver;
var driver = new Chromedriver;
driver.get('https://my.test.url');
var myButton = driver.findElement(By.cssSelector('[id*=CLICK_ME]'));
myButton.click();
It tries to run - browser is launched, and page starts to load... but the steps are not executed synchronously - it goes on and tries to find and click "myButton" before the page has finished loading, throwing a "no such element" error... which to me kinda defeats the point of webdriver-sync?! Can someone tell me where I am going wrong?
FWIW, I have webdriver-sync 1.0.0, node v7.10.0, java 1.8.0_74, all running on CentOS 7.
Thanks in advance!
You need to put double-quotes around "CLICK_ME" as it's a string value.
Generally, though, it's a good idea to Wait for specific elements because dynamic pages are often "ready" before all their elements have been created.

Cannot get QWindow::fromWinId to work properly

My Qt 5.9 program (on X11 Linux) launches other applications, using QProcess.
I would like to have control over windows these applications spawn, so I obtain their winId value and use QWindow::fromWinId to get a QWindow instance.
The problem is these instances are invalid and do not represent the window they are supposed to.
If I check the winId values using xwininfo, the correct information is returned, so I know they are good.
What am I doing wrong?
Edit: An example won't help much, but here goes:
QProcess *process=new QProcess(this);
...
process.open()
... // wait until window appears
WId winId=PidToWid(process->processId()); // this function returns the Window ID in decimal format. I test this with xwininfo, it's always correct
...
QWindow *appWindow=QWindow::fromWinId(winId);
... And that's basically it. appWindow is a valid QWindow instance, but it does not relate to the actual window in any way. For example, if I close() it, it returns true but the window does not close.
Even if I provide a wrong WId on purpose, the end result is the same.
This is not proper solution with explanation why it should work, however it may be helpful for somebody...
I had the same issue with my application when I switched from Qt4 QX11EmebeddedContainer to Qt5 implementation using QWindow. What I did to resolve / fix this issue was following:
Client application:
widget->show(); //Widget had to be shown
widget->createWinId();
sendWinId(widget->winId()); //Post window handle to master app where is constructed container
Master application:
QWindow* window = QWindow::fromWinId(clientWinId);
window->show(); //This show/hide toggle did trick in combination with show in client app
window->hide();
QWidget* container = QWidget::createWindowContainer(window, parentWindowWidget);
After this I was able to control window properly through QWidget container.

How to compile and spawn/run the projects(http and worker) from a main application?

I'm trying to learn D and hence setting upp a httpserver with a worker thread that can do stuff in its own loop ie. a main application that starts up by spawning http thread and the worker thread then also connect signal (SIGINT, &handler) to handle like Ctrl + C in main where handler function is in each spawned threads.
I'm using Vibe.d for the http server.
The folder structure, where the root folder is the main application and with separate subfolders for http and worker project
Now my problem is the spawn part, how to get the worker going if that is its own project?
I've tried to import worker project but no luck
I can't compile as I've learned the three .d files on a row
dub source/app.d aworker/source/app.d
This gives me an error "The source file must start with a recipe comment"???
Answer to that you can see in dub commandline params
I've managed to spawn threads using dmd syntax but within same project in "call function in another file" question, now I want to separate projects as if a group of people are coding them separatly.
How do I compile and spawn/run several projects(http and worker) from a main application??
I have found the solution to my problem. spawnProcess
Read more about it at dlang.org and spawnProcess
1) In my project group "spider", "server" and "worker", i have compiled all to individual applications using dub in resp. project folder.
2) From the "spider" application code, I thread out "server" and "worker" as subprocesses like this
import std.process;
auto workerId = spawnProcess(<path to worker as string>);
scope(exit)wait(workerId);
auto serverId = spawnProcess(<path to server as string>);
scope(exit)wait(serverId);
This leaves me with a single starting point and I run from a terminal, then it's the single terminal with all output like writeln a.s.o. from all processes.
Still left to solve signal, but that looks like a minor problem ;)

Resources