Open up a Terminal and type:
sudo alsamixer
Now using your left/right arrow keys navigate over to PC Beep
and press M
on your keyboard, you'll see MM
appear under the volume bar, this basically means it's been muted now press Esc
to exit.
Open up a Terminal and type:
sudo alsamixer
Now using your left/right arrow keys navigate over to PC Beep
and press M
on your keyboard, you'll see MM
appear under the volume bar, this basically means it's been muted now press Esc
to exit.
* Object level lock.
* Python Synchronized method.
* Here variable 'lock' is an instance variable.
* So each object has its own instance variable 'lock'.
* Suppose object 'a' acquire a lock on function 'first_function', this time
object 'b' can call and acquire lock on function 'first_method', without out waiting for
object 'a' to release the lock.
import threading
class A:
def __init__(self):
#For private variable use single underscore before variable name.
#self._lock = threading.RLock()
self.lock = threading.RLock()
def first_function(self, name):
print "------first_function, Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------first_function, lock acquired------", name
print "------first_function, sleeping----start----", name
import time
time.sleep(5)
print "------first_function, sleeping----end------", name
finally:
self.lock.release()
print "------ first_function, lock released-------", name
def second_function(self, name):
print "------second_function, Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------second_function, lock acquired------", name
print "------second_function, sleeping----start----", name
import time
time.sleep(5)
print "------second_function, sleeping----end------", name
finally:
self.lock.release()
print "------second_function, lock released-------", name
a = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.first_function', target=a.first_function, args=('T2',))
print "----------calling------thr1.start()------"
thr1.start()
print "----------calling------thr2.start()------"
thr2.start()
----------------------------------------------------CASE-1
2 threads 'thr1' and 'thr2' trying to call a method 'first_function' of class 'A'
using same object 'a'.
a = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.first_function', target=a.first_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------first_function, Waiting for acquire lock------ T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------first_function, lock acquired------ T2
------first_function, sleeping----start---- T2
------first_function, sleeping----end------ T2
------ first_function, lock released------- T2
----------------------------------------------------CASE-2
2 threads 'thr1' and 'thr2' trying to call two seperate methods 'first_function'
and 'second_function' of class 'A' using same object 'a'.
a = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='a.second_function', target=a.second_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------second_function, Waiting for acquire lock------ T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------second_function, lock acquired------ T2
------second_function, sleeping----start---- T2
------second_function, sleeping----end------ T2
------second_function, lock released------- T2
----------------------------------------------------CASE-3
2 threads 'thr1' and 'thr2' trying to call a method 'first_function' of class 'A'
using different objects 'a' and 'b'.
a = A()
b = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='b.first_function', target=b.first_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
------first_function, Waiting for acquire lock------ T1
------first_function, lock acquired------ T1
----------calling------thr2.start()------
------first_function, sleeping----start---- T1
------first_function, Waiting for acquire lock------ T2
------first_function, lock acquired------ T2
------first_function, sleeping----start---- T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------first_function, sleeping----end------ T2
------ first_function, lock released------- T2
----------------------------------------------------CASE-4
2 threads 'thr1' and 'thr2' trying to call two seperate methods 'first_function' and
'second_function' of class 'A' using two seperate objects 'a' and 'b'.
a = A()
b = A()
thr1 = threading.Thread(name='a.first_function',target=a.first_function, args=('T1',))
thr2 = threading.Thread(name='b.second_function', target=b.second_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
------first_function, Waiting for acquire lock------ T1
----------calling------thr2.start()------
------first_function, lock acquired------ T1
------first_function, sleeping----start---- T1
------second_function, Waiting for acquire lock------ T2
------second_function, lock acquired------ T2
------second_function, sleeping----start---- T2
------first_function, sleeping----end------ T1
------ first_function, lock released------- T1
------second_function, sleeping----end------ T2
------second_function, lock released------- T2
==================================
* Class level lock.
* Here variable 'lock' is a class variable.
* So all objects using common lock.
* Here at a time only one object can acquire lock.
* Suppose object 'a' call the method 'my_function' and acquire the lock,
this time object 'b' or other objects can method 'my_function' but can not
acquire the lock until object 'a' release the lock, so object 'b' waiting in method
'my_function' for
acquire the lock.
import threading
class A:
lock = threading.RLock()
def my_function(self, name):
print "------Waiting for acquire lock------", name
self.lock.acquire()
try:
print "------lock acquired------", name
print "------sleeping----start----", name
import time
time.sleep(5)
print "------sleeping----end------", name
finally:
self.lock.release()
print "------lock released-------", name
a = A()
b = A()
thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='b.my_function', target=b.my_function, args=('T2',))
print "----------calling------thr1.start()------"
thr1.start()
print "----------calling------thr2.start()------"
thr2.start()
----------------------------------------------------CASE-1
2 threads 'thr1' and 'thr2' trying to call a method 'my_function' of class 'A'
using two seperate objects 'a' and 'b'.
a = A()
b = A()
thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='b.my_function', target=b.my_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------Waiting for acquire lock------ T1
------lock acquired------ T1
------sleeping----start---- T1
------Waiting for acquire lock------ T2
------sleeping----end------ T1
------lock released------- T1
------lock acquired------ T2
------sleeping----start---- T2
------sleeping----end------ T2
------lock released------- T2
----------------------------------------------------CASE-2
a = A()
thr1 = threading.Thread(name='a.my_function',target=a.my_function, args=('T1',))
thr2 = threading.Thread(name='a.my_function', target=a.my_function, args=('T2',))
OUTPUT
======
----------calling------thr1.start()------
----------calling------thr2.start()------
------Waiting for acquire lock------ T1
------lock acquired------ T1
------sleeping----start---- T1
------Waiting for acquire lock------ T2
------sleeping----end------ T1
------lock released------- T1
------lock acquired------ T2
------sleeping----start---- T2
------sleeping----end------ T2
------lock released------- T2
==================================
Here is a guide to help you setup your own On Demand Streaming System. We will be doing this using a nifty platform called Ampache – the Apache Amplifier.
Ampache has the ability to allow multiple users access the data, create sessions and personalized playlists. According to the website - Ampache is a web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any Internet enabled device.
This means, once set up, you can stream to any device -- Android phones, tablets, netbook and of course laptops & desktops -- which can connect to your network.
All you need is a PC running a GNU/Linux operating system. In this guide we are using Ubuntu, you can use any Linux distro of your choice.
You will need a working AMP (Apache, MySQL, PHP) setup. In Ubuntu, install the three software packages using Synaptic. If you are the adventurous type, you may also install the components individually and go about configuring each manually. This is a fun learning process, but only if you want to get your hands really dirty! You may also want to install the MySQL GUI Tools in case any problems arise and you need to do some under-the-hood fiddling.
While working in a project, we all need to share various files and directories to our peers. It sometimes happens that a file gets deleted by mistake by the peers while working with it. In that case, if you do not have a backup of the file then a lot of hardwork gets wasted.
So, in Unix like system there are permission bits which let you chose what permission (read, or write, or execute, or all the three) do you want to give to a group, user, or others. But there is a fourth protection bit called the Sticky bit and it helps secure your files.
There are two major benefits of this Sticky Bit:
Today memory has become cheap, so it is not so important to have sticky bit on for regular files. But when it comes to directories it is a really useful feature. The Sticky bit is by default set on in the /tmp directory. So, anyone can create any files or directory into the /tmp, but cannot delete other users files which are create there.
The sticky bit is useful for implementing group projects. Let us consider the situation, when a group of users work on a set of files without infringing on security...
1. Create a common group for the users in /etc/projects
2. Create seperate user accounts for each of them but specify the same home directory
3. Make sure the home directory and all subdirectories are not owned by any of the users.
4. Then, set the permission to group writeable abd set the sticky bit.
$ chmod 1775 [filename] or [directory], where chmod stands for 'change file mode bits'. For more information, type 'man chmod' on your terminal.
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'a.ui'
#
# Created: Sat Oct 2 02:08:21 2010
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(QtGui.QMainWindow):
def __init__(self):
self.widget=QtGui.QMainWindow()
self.setupUi(self.widget)
def setupUi(self, MainWindow):
self.widget.setGeometry(QtCore.QRect(0, 0, 500, 500))
MainWindow.setObjectName("MainWindow")
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.but_show_proc = QtGui.QPushButton(self.centralwidget)
self.but_show_proc.setGeometry(QtCore.QRect(100, 400, 93, 27))
self.but_show_proc.setObjectName("but_show_proc")
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(90, 30, 340, 341))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(0)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.but_shutdown = QtGui.QPushButton(self.centralwidget)
self.but_shutdown.setGeometry(QtCore.QRect(260, 400, 93, 27))
self.but_shutdown.setObjectName("but_shutdown")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 549, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
QtCore.QObject.connect(self.but_shutdown,QtCore.SIGNAL("clicked()"),self.shutdown)
QtCore.QObject.connect(self.but_show_proc,QtCore.SIGNAL("clicked()"),self.show_process)
self.show_process()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def show_process(self):
try:
import subprocess as subp
f1 = subp.Popen(['ps', '-au'], stdout = subp.PIPE)
lines = []
for l in f1.stdout.readlines():
lines.append(l)
self.tableWidget.setRowCount(len(lines[1:]))
r = 0
for x in lines[1:]:
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[6])
self.tableWidget.setItem(r,0,item)
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[8])
self.tableWidget.setItem(r,1,item)
item=QtGui.QTableWidgetItem()
item.setText(x.split(' ')[10])
self.tableWidget.setItem(r,2,item)
r += 1
except Exception, e:
print e
def shutdown(self):
import subprocess as subp
subp.Popen('poweroff')
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow",
"Task Manager", None, QtGui.QApplication.UnicodeUTF8))
self.but_show_proc.setText(QtGui.QApplication.translate("MainWindow",
"Refresh", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(0).setText(QtGui.QApplication.
translate("MainWindow", "PID", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(1).setText(QtGui.QApplication.
translate("MainWindow", "Cpu", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(2).setText(QtGui.QApplication.
translate("MainWindow", "Mem", None, QtGui.QApplication.UnicodeUTF8))
self.but_shutdown.setText(QtGui.QApplication.translate("MainWindow",
"Shutdown", None, QtGui.QApplication.UnicodeUTF8))
import sys
if __name__ == "__main__":
app=QtGui.QApplication(sys.argv)
obj=Ui_MainWindow()
obj.widget.show()
sys.exit(app.exec_())
>>> l = [1]
>>>
>>> n = {'a':2,'b':3} <--------dict
>>>
>>> l.extend(n)
>>> l
[1, 'a', 'b'] <------- Note: taken only keys
>>> n = (8,9) <--------Tuple
>>> l.extend(n)
>>> l
[1, 'a', 'b', 8, 9]
>>>
>>> a = [1]
>>>
>>>
>>> isinstance(a , list)
True
>>> isinstance(a , (list))
True
>>> isinstance(a , tuple)
False
>>> isinstance(a , (tuple))
False
>>> isinstance(a , (tuple, list))
True
>>> isinstance(a , (tuple, list, dict))
True
>>> a = (1)
>>> isinstance(a , (tuple, list, dict))
False
>>> a = (1,)
>>> isinstance(a , (tuple, list, dict))
True
>>> a = {'n':1}
>>> isinstance(a , (tuple, list, dict))
True
>>>
=======================