unable to move an object to a thread - python-3.4

I'm currently building a small serial monitor. It's based on two main class: SerialSender and SerialListener. These run infinite loop, so they should be placed in theyr own thread.
There is a minimal code reproducing the bad comportment of my programm:
sender = SerialSender()
listener = SerialListener()
sender_thread = QThread()
listener_thread = QThread()
sender.moveToThread(sender_thread)
listener.moveToThread(sender_thread)
print("Main thread is: {mt}\n"
"Sender thread is: {st}\n"
"Listener thread is: {lt}".format(
mt = int(QThread.currentThreadId()),
st = int(sender.thread().currentThreadId()),
lt = int(listener.thread().currentThreadId()))
With this code, we can expect to have three different thread ids, but I get:
Main thread is: 139968246126400
Sender thread is: 139968246126400
Listener thread is: 139968246126400
Where does this come from ?

Related

I got some signal problems when I attempt to spawn multiple nodes

My intend is to spawn node (I will say Stickman for now) on a specific position and make them move to left and right using buttons.
As you can see, I have two buttons to move my Stickman. The Attack button will move the Stickman to the right, while the Defense button will move it to the left. The small button from the right is used to spawn the stickman.
Things work like a charm, yes
The issues occurs when I try to spawn another Stickman. For some reasons the signal is cut with the second Stickman, which I believed is because I only connected my signal to Stickman's node, but in this case its currently rename as Stickman2, Stickman3 and so on.
The problem reveals itself
Here is the code of my stickman:
extends KinematicBody2D
var speed = 30
var velocity = Vector2.ZERO
onready var enemy_base = get_node("../Position/enemy_base").global_position
onready var allied_base = get_node("../Position/allied_base").global_position
enum {
ATTACK,
DEFENSE,
RETREAT
}
var state = DEFENSE
func _physics_process(delta):
match state:
ATTACK:
attack(delta)
DEFENSE:
defense(delta)
func attack(delta):
var direction = (enemy_base - global_position).normalized()
var desired_velocity = direction * speed
var steering = (desired_velocity - velocity) * delta * 2.5
velocity += steering
velocity = move_and_slide(velocity)
func defense(delta):
var direction = (allied_base - global_position).normalized()
var desired_velocity = direction * speed
var steering = (desired_velocity - velocity) * delta * 2.5
velocity += steering
velocity = move_and_slide(velocity)
func _on_Attack_pressed():
state = ATTACK
func _on_Defense_pressed():
state = DEFENSE
And this is the spawning code I used:
extends Node2D
var Stickboi = preload("res://StickBoy.tscn")
var Swordman = Swordman
func _on_StickBoi_pressed():
Swordman = Stickboi.instance()
Swordman.global_position = $Position/behind_allied_base.global_position
add_child(Swordman)
func _on_Attack_pressed():
Swordman.state = Swordman.ATTACK
func _on_Defense_pressed():
Swordman.state = Swordman.DEFENSE
I want all my Stickmans to react to my signal whenever I pressed the Attack or Defense buttons, which in this case doesn't work at all. I really appreciate if you have any ideas that could share, even if its just a hint. I'm still a beginner and I acknowledge my stupidity, so sorry to ask such simple question and also my bad English grammars. Please ask if there are anything you want to know in case my explanation is such simple, I will try my best to answer as fast as possible. Once again, thank you for your help.
I don't see you connect the signals.
Instead, it appears to me, that the signals are connected to the Node2D that has the spawning code. And it calls into the Swordman instance, which is the last instance it created.
You can actually connect the signals.
I'm guessing that the Node2D that has the spawning code is the parent of the buttons.
First of all, you will have no need to keep a reference to the instance. Nor will you connect the buttons to the Node2D that has the spawning code. I'm getting rid of that:
extends Node2D
var Stickboi = preload("res://StickBoy.tscn")
func _on_StickBoi_pressed():
var swordman = Stickboi.instance()
swordman.global_position = $Position/behind_allied_base.global_position
add_child(swordman)
Instead we are going to connect the buttons to the instance (you seem to have conveniently created methods for that, so I'll use them).
extends Node2D
var Stickboi = preload("res://StickBoy.tscn")
func _on_StickBoi_pressed():
var swordman = Stickboi.instance()
$Attack.connect("pressed", swordman, "_on_Attack_pressed")
$Defense.connect("pressed", swordman, "_on_Defense_pressed")
swordman.global_position = $Position/behind_allied_base.global_position
add_child(swordman)
And that should work.

Re-trigger scheduled instances with SAP BO API?

I want to re-trigger all the failed schedules using a java jar file on CMS.
Just for testing I wrote this below program which i suppose would re-trigger a certain schedule, which completed successfully.
Please help me find where did i go wrong since it shows success when I run this program on CMS but the schedule doesn't get triggered
public class Schedule_CRNA implements IProgramBase {
public void run(IEnterpriseSession enterprisesession, IInfoStore infostore, String str[]) throws SDKException {
//System.out.println("Connected to " + enterprisesession.getCMSName() + "CMS");
//System.out.println("Using the credentials of " + enterprisesession.getUserInfo().getUserName() );
IInfoObjects oInfoObjects = infostore.query("SELECT * from CI_INFOOBJECTS WHERE si_instance=1 and si_schedule_status=1 and SI_ID=9411899");
for (int x = 0; x < oInfoObjects.size(); x++) {
IInfoObject oI = (IInfoObject) oInfoObjects.get(x);
IInfoObjects oScheds = infostore.query("select * from ci_infoobjects,ci_appobjects where si_id = " + oI.getID());
IInfoObject oSched = (IInfoObject) oScheds.get(0);
Integer iOwner = (Integer) oI.properties().getProperty("SI_OWNERID").getValue();
oSched.getSchedulingInfo().setScheduleOnBehalfOf(iOwner);
oSched.getSchedulingInfo().setRightNow(true);
oSched.getSchedulingInfo().setType(CeScheduleType.ONCE);
infostore.schedule(oScheds);
oI.deleteNow();
}
}
}
It seems you missed the putting of your retrieved scheduled object into collection.
The last part in your snippet should be:
oSched.getSchedulingInfo().setScheduleOnBehalfOf(iOwner);
oSched.getSchedulingInfo().setRightNow(true);
oSched.getSchedulingInfo().setType(CeScheduleType.ONCE);
IInfoObjects objectsToSchedule = infostore.newInfoObjectCollection();
objectsToSchedule.add(oI);
infostore.schedule(objectsToSchedule);
oI.deleteNow();
You cannot schedule report directly but rather through collection. Full sample is here.
Also your coding deleting object from repository and rescheduling it again with each iteration seems weird, but it is up to your requirement.

Robot Framework: Timed out waiting for page load

We have run our Robot Framework environment nearly one year without any problems, but now we get the error message:
TimeoutException: Message: Timed out waiting for page load.
Stacktrace:
at Utils.initWebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:9089)
at WebLoadingListener/e (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5145)
at WebLoadingListener/< (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:5153)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///tmp/tmp77bOby/webdriver-py-profilecopy/extensions/fxdriver#googlecode.com/components/driver-component.js:625)
What could be problem? I checked the disk space and there are disk space left.
A timeout error can have a laundry list of possible issues. Loading a page after a year of smooth operation narrows it down a little, but there are still many possibilities. Connection speeds sometimes change, sometimes the page you're loading up has added features that cause it to take longer to load or was just written poorly so it loads slowly... you get the idea. Without the code of the page or your code to look at, I can only suggest two fixes.
First, in the code of Selenium2Library, there is a timeout variable somewhere that can be set with Set Selenium Timeout. The default is 5 seconds, but if your page is taking longer to load, then increasing it might solve your problem. This assumes that your page loads at a reasonable rate in manual testing and that opening it is the least of your concerns.
Second, it's possible that you're testing an AngularJS application, not a normal website. If that's true, then you're going to want to use ExtendedSelenium2Library, not Selenium2Library. ExtendedSelenium2Library is better-equipped to deal with AngularJS applications and includes code to wait for Angular applications to load.
The old webdriver.xpi is buggy about page load handling. Timers are not correctly canceled, resulting in random windows switches and memory leaks. I copy here some replacement code that may be useful to anybody.
var WebLoadingListener = function(a, b, c, d) {
if ("none" == Utils.getPageLoadStrategy()) {
b(!1, !0);
} else {
this.logger = fxdriver.logging.getLogger("fxdriver.WebLoadingListener");
this.loadingListenerTimer = new fxdriver.Timer;
this.browser = a;
var self = this;
var e = function(a, c) {
self.destroy ();
b(a, c);
};
this.handler = buildHandler(a, e, d);
a.addProgressListener(this.handler);
-1 == c && (c = 18E5);
this.loadingListenerTimer.setTimeout(function() {
e(!0);
}, c);
WebLoadingListener.listeners [this.handler] = this;
goog.log.warning(this.logger, "WebLoadingListener created [" + Object.keys (WebLoadingListener.listeners).length + "] " + d.document.location);
}
};
WebLoadingListener.listeners = {};
WebLoadingListener.removeListener = function(a, b) {
if (b.constructor !== WebLoadingListener) {
b = WebLoadingListener.listeners [b];
}
b.destroy ();
};
WebLoadingListener.prototype.destroy = function() {
if (this.browser) {
this.loadingListenerTimer.cancel();
this.browser.removeProgressListener && this.handler && this.browser.removeProgressListener(this.handler);
delete WebLoadingListener.listeners [this.handler]
this.loadingListenerTimer = undefined;
this.browser = undefined;
goog.log.warning(this.logger, "WebLoadingListener destroyed [" + Object.keys (WebLoadingListener.listeners).length + "]");
}
};
enter code here

How to set focus on a client under mouse cursor when a tag is changed?

When I switch to another tag, a new client gets selected, but it is sometimes not a client that I have my mouse cursor over. To get a client under my mouse pointer focused, I have to either click somewhere on it, or switch to it with Mod4+j / k, or move mouse cursor out and back on that client.
I want awesome to give focus to a client that is under the mouse cursor whenever a tag is changed. How do I do that?
I found a function mouse.object_under_pointer() that finds the client I need, but I don't know when to call that function. Should I connect a handler to some particular signal? I tried connecting to various signals from Signals page on the wiki and checking with naughty.notify() if that is the right signal, but none of them were triggered when I was switching between tags.
This code did the trick, however there should be a better way to do this than setting up a huge 200 ms timer (smaller timeouts didn't properly focus some clients for me, but you can try setting a smaller one).
tag.connect_signal(
"property::selected",
function (t)
local selected = tostring(t.selected) == "false"
if selected then
local focus_timer = timer({ timeout = 0.2 })
focus_timer:connect_signal("timeout", function()
local c = awful.mouse.client_under_pointer()
if not (c == nil) then
client.focus = c
c:raise()
end
focus_timer:stop()
end)
focus_timer:start()
end
end
)
tag is this global object, so you should just place this code anywhere in your rc.lua.
Two things should be done:
First, you should remove require("awful.autofocus") from your config, so that this module no longer tries to focus some client via the focus history when you switch tags.
Then, this code works for me:
do
local pending = false
local glib = require("lgi").GLib
tag.connect_signal("property::selected", function()
if not pending then
pending = true
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
pending = false
local c = mouse.current_client
if c then
client.focus = c
end
return false
end)
end
end)
end
This uses GLib directly to get a callback for when no other events are pending. This should mean that "everything else" was handled.
I know this is pretty old, but it helped me to come up with this
function focus_client_under_mouse()
gears.timer( { timeout = 0.1,
autostart = true,
single_shot = true,
callback = function()
local n = mouse.object_under_pointer()
if n ~= nil and n ~= client.focus then
client.focus = n end
end
} )
end
screen.connect_signal( "tag::history::update", focus_client_under_mouse )

Using scanner and multi variable arrays

So, I have this tiny problem. I'm prompting the user to input 3 variables (Str, Str, Int) that need to be stored in a multi variable array and I can't get it to work. Any help will be appreciated.
LibraryBook[] book = new LibraryBook[5];
//inputing a new book
Scanner input = new Scanner(System.in);
LibraryBook[] myBook = new LibraryBook[0];
System.out.println("Enter book name: ");
String title = input.nextLine().trim();
System.out.println("Enter author name: ");
String author = input.nextLine().trim();
System.out.println("Enter # pages: ");
int pages = input.nextInt();
myBook[0] =new LibraryBook(title,author,pages);
I get this error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at LibraryBookSort.main(LibraryBookSort.java:36)
----jGRASP wedge2: exit code for process is 1.
delete this line
LibraryBook[] myBook = new LibraryBook[0];
and replace last line
myBook[0] =new LibraryBook(title,author,pages);
by this
book[0] =new LibraryBook(title,author,pages);
You're initializing your array with zero size, so you basically don't have any space to store a variable (a class in your case). Here's the correction:
LibraryBook[] myBook = new LibraryBook[10];
I'm assuming you will need no more than 10 locations in your program.
Edit: I just noticed you have two LibraryBook arrays declared, but you're only using one. Is there a necessity for the unused one?

Resources