Hi, 

I'm trying to integrate libzypp to a daemon which is written in python. I'm 
using SLES12 with the following components:

zypper- 1.12.45 -31.2.x86_64 
libzypp- 15.23.1-30.1 .x86_64 
python-zypp-0.7.3-1.6.x86_64 

It's working pretty good but unfortunately, it does block zypper from being 
used as the daemon will keep the "lock" even if the zypp object is destroyed. 

I have attached 3 examples which illustrates the issue: 
- testZ.py will just initate the zypp library and then sleep forever in a while 
loop. 
- testThread.py will do the same but will initate the zypp library in a 
separate thread 
- testProcess.py will use a new process instead of a thread 

Just start the test application and then try to use zypper in a second shell 
e.g. zypper search which will then show the following message: 

System management is locked by the application with pid 18852 (python). 
Close this application before trying again. 


The same happpens for testThread.py. testProcess.py does work as the process in 
which zypp was initiated will be terminated and everything is free'd. 


Does someone know how to get the testZ.py example running? I don't want to 
start a process (or thread) for doing the zypp stuff within the daemon. Would 
be great if there is a better solution. 

Thank you in advance. 


Best regards, Bernhard Suttner 
______________________________________________________ 
ATIX - The Linux & Open Source Company 
#!/usr/bin/python

from multiprocessing import Process
import zypp
import time

def f(name):
	print "before getZypp"
	Z = zypp.ZYppFactory_instance().getZYpp()

        # Load all enabled repositories...
        repoManager = zypp.RepoManager()
        for repo in repoManager.knownRepositories():
        	if not repo.enabled():
			continue
		if not repoManager.isCached(repo):
			repoManager.buildCache(repo)
		repoManager.loadFromCache(repo);

        # Now all installed and available items are in the pool:
        print ("Known items: %d" % (Z.pool().size()))

	print "End of getZypp"

if __name__ == '__main__':
	p = Process(target=f, args=('bob',))
	p.start()
	p.join()

	print "before loop"

	while True:
		print "Trying..."

		#if zypp.ZYppFactory_instance().haveZYpp():
		#    print ("Sleeping and having ZYpp")
		#else:
		#    print ("Sleeping without having ZYpp")
		time.sleep(1)

#!/usr/bin/python

from thread import start_new_thread

from zypp import getZYpp
import time

def myt(a):

	print "before getZypp"
	Z = getZYpp()

	#Z = zypp.ZYppFactory_instance().getZYpp()
	#zypp.ZYppFactory_instance().reset()
	Z.reset()
	del Z
	Z = None
	print "End of thread"


print "before thread"
start_new_thread(myt,(1,))

while True:
	print "Trying..."

	#if zypp.ZYppFactory_instance().haveZYpp():
	#    print ("Sleeping and having ZYpp")
	#else:
	#    print ("Sleeping without having ZYpp")
	time.sleep(1)

#!/usr/bin/python

from zypp import getZYpp
import time

print "before getZypp"
Z = getZYpp()

#Z = zypp.ZYppFactory_instance().getZYpp()
#zypp.ZYppFactory_instance().reset()
Z.reset()
del Z
Z = None

print "before loop"

while True:
	print "Trying..."

	#if zypp.ZYppFactory_instance().haveZYpp():
	#    print ("Sleeping and having ZYpp")
	#else:
	#    print ("Sleeping without having ZYpp")
	time.sleep(1)

Reply via email to