473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Queue and signals

hg
Hi,

Is it legal to use Queue.put in a signal handle and Queue.get in the main
process (no thread)

Thanks,

hg

Jan 16 '07 #1
3 2406
hg
hg wrote:
Hi,

Is it legal to use Queue.put in a signal handle and Queue.get in the main
process (no thread)

Thanks,

hg

PS: and if not is there a way to share data between a "main" and its signal
in a safe way (write in signal and read in main)

Thanks,

hg

Jan 16 '07 #2
>Is it legal to use Queue.put in a signal handle and Queue.get in the
main process (no thread)
hgPS: and if not is there a way to share data between a "main" and its
hgsignal in a safe way (write in signal and read in main)

The Queue module was designed to work in multithreaded contexts. I doubt it
will work as expected in a nonthreaded application. Given that your
application isn't multithreaded I suspect you can just modify an object that
both your signal handler and the rest of the application reference. In
particular, there's no reason your signal handler can't be a method of an
instance:

import signal
import time

class MyClass:
def __init__(self):
self.alarm_rang = False
signal.signal(signal.SIGALRM, self.ring_alarm)
signal.alarm(2)

def ring_alarm(self, sig, frame):
self.alarm_rang = True

obj = MyClass()
print obj.alarm_rang
time.sleep(4.0)
print obj.alarm_rang

Skip
Jan 17 '07 #3
hg
sk**@pobox.com wrote:
>
>Is it legal to use Queue.put in a signal handle and Queue.get in
>the main process (no thread)

hgPS: and if not is there a way to share data between a "main" and
its hgsignal in a safe way (write in signal and read in main)

The Queue module was designed to work in multithreaded contexts. I doubt
it
will work as expected in a nonthreaded application. Given that your
application isn't multithreaded I suspect you can just modify an object
that
both your signal handler and the rest of the application reference. In
particular, there's no reason your signal handler can't be a method of an
instance:

import signal
import time

class MyClass:
def __init__(self):
self.alarm_rang = False
signal.signal(signal.SIGALRM, self.ring_alarm)
signal.alarm(2)

def ring_alarm(self, sig, frame):
self.alarm_rang = True

obj = MyClass()
print obj.alarm_rang
time.sleep(4.0)
print obj.alarm_rang

Skip
Hi,

Well, so far it seems to work ...

The signal handler gets "called" by another application which in turn will
stuff info in my sys.stdin, I need then to "raw_input" the info and put it
in some type of data structure in a safe way so my main loop can then
reader/pop it.

ref: (ps: I'm trying to setup a Python high level interface for my kids to
learn the language / be interested) http://realtimebattle.sourceforge.net/

Regards,

hg
Jan 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Paul L. Du Bois | last post by:
Has anyone written a Queue.Queue replacement that avoids busy-waiting? It doesn't matter if it uses os-specific APIs (eg WaitForMultipleObjects). I did some googling around and haven't found...
1
by: Isidro Vila Verde | last post by:
Greetings, I need to handle signals to close some excel applications that my script open, when the script is killed by another process. My script is a little bit complex, but I wrote just two ...
4
by: Gabriele Bartolini | last post by:
Hi, I am writing an application in C++ on Linux, using threads (this is my first experience with pthreads). The application itself is fine, it is just that I wanted to handle asynchronous...
1
by: Leo Kirch | last post by:
Hello XSLT gurus, i've got a rather difficult problem. Some explanations first. theres a signal oriented xml-file - the graphical represantation looks like: | startsignal (signal00) \...
4
by: maxmagna | last post by:
Hello, I am looking for material that describes how *precisely* UNIX-based signals interact with the normal C++ execution flow of control and guidelines on how to treat signals in an...
0
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have...
11
by: vippstar | last post by:
What is the purpose of signals and why do they exist in C? thanks in advance
1
by: davidcollins001 | last post by:
Hi, I am trying to implement a blocked or synchronous method of message passing using signal interrupts. So far I have the following: server.c { msgget(queue) msgrcv (queue mtype) ...
2
by: wongjoekmeu | last post by:
Dear All, I have some a program in which I link a static library. The static library has a initialize() and uninitialized() function. Now when I call the initialize function a thread is being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.