Bug 972429

Summary: BodhiClient is not working properly if running in thread and from interative interpreter
Product: [Fedora] Fedora Reporter: Branislav Blaškovič <bblaskov>
Component: python-fedoraAssignee: Toshio Ernie Kuratomi <a.badger>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 18CC: a.badger, jstanley, lmacken, ricky
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-06-09 15:27:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Bodhi reproducer none

Description Branislav Blaškovič 2013-06-09 10:42:27 UTC
Created attachment 758721 [details]
Bodhi reproducer

Description of problem:
  BodhiClient is not working when it's invoked from python interactive interpreter and running in Thread

Version-Release number of selected component (if applicable):
  python-fedora-0.3.32.3-1.fc18.noarch
  python-fedora-0.3.32.3-1.fc17.noarch

How reproducible:
  always

Steps to Reproduce:

  Try to run attached file as:
    $ python bodhiqthread.py

  Then firstly run python interpreter and then import bodhiqthread
    $ python
    >>> import bodhiqthread

Actual results:
  If running in interactive python interpreter, Bodhi never return results.

Expected results:
  Some results from Bodhi.

Additional info:
  I've tested this on F17 and F18 as well.

Comment 1 Branislav Blaškovič 2013-06-09 11:28:53 UTC
It is also reproducable if you create new python file and fill it with:

  import bodhiqthread

So the problem is not with interactive interpreter but when it's imported as library.

Comment 2 Toshio Ernie Kuratomi 2013-06-09 15:27:55 UTC
We ran through some debugging over IRC and think we figured this out.  The python stdlib threading docs say this:

http://docs.python.org/2.7/library/threading.html#importing-in-threaded-code

Firstly, other than in the main module, an import should not have the side effect of spawning a new thread and then waiting for that thread in any way. Failing to abide by this restriction can lead to a deadlock if the spawned thread directly or indirectly attempts to import a module.

What we think is happening in the example is that bodhiqthread() is spawning the thread as a side effect.  Removing the call to Starter() from bodhiqthread() and instead calling bodhiqthread.Starter() from the python prompt works.  It should be possible to restructure the program so that the new thread is only spawned from a function or method call, not as a side effect of importing.

Feel free to reopen if you find that this is not what's happening.