ctghvorukaaowmo

PyCon India 2016

Heya! First of all I’m really sorry for such a delay with PyCon India 2016 blog post.

It was my first PyCon India. I have always wanted to attend such nice conference. But somehow I was probably going to miss it because of fund. It was only DGPLUG for which I could attend PyCon India 2016. They made sure about my travelling from Pune to Delhi and my accommodation. Have a look at 🙂 https://kushaldas.in/posts/dgplug-contributor-grant-recipient-trishna-guha.html.

DAY 1 started with Workshop and Openspace. I stayed in the Openspace since I didn’t buy ticket for workshop. I came to know about an useful project Ansible-Container from Shubham Miglani. We started hacking on the project. I also created an issue for the project but couldn’t work on the patch since the patch was already fixed and out with next release.

I met many of the faces whom I used to know on IRC/Twitter only. It was really exciting and my first day of the conference was over.

The main conference started from Day 2. It started with Keynote by Baishampayan Ghose. He gave a nice keynote on building bridges, distributed architecture and functional testing. Then the other talks carried on.  I was at the Red Hat and PyLadies booth most of the time.

We had a keynote by VanL as well about software design and failure which was great.

Many people came down with the interest about internship at Red Hat and joining PyLadies Community. We had DGPLUG + PyCon India Dinner at BBQ- Delhi later at night.

Day 3 started with Keynote by Andreas Muller on Machine Learning. Then multiple tracks talks carried on. I really enjoyed microservices talk by Ratnadeep Debnath. We had DGPLUG staircase meeting. There after we had open discussion on PyLadies – Diversity and FOSS community with Paul Everitt, Dmitry Filippov, VanL.

There was Red Hat sponsored talk by Kushal Das.

Oh yes I gave a short lightning talk on Project Atomic and Fedora Infrastructure Application Bodhi as well. The day ended with DGPLUG photo shoot.

We had dinner outside and headed back to Pune that night.

Below are the few photos I have :-).

ctqgad2vmaag13g

29313770323_05feccdc10_z

For more photos visit: https://www.flickr.com/photos/sayanchowdhury/albums/72157674406421245

We are going to have another conference on Python really soon Pycon Pune 2017 :-).

screenshot-from-2016-09-30-14-21-47

What is if __name__ == ‘__main__’ ?

 

Module is simply Python file that has .py extension. Module can contain variables, functions, classes that can be reused.

In order to use module we need to import the module using import command. Check the full list of built-in modules in Python here https://docs.python.org/3.6/library.

The first time a module is loaded in to running Python script, it is initialized by executing the code in the module once. To know various ways of importing modules visit here: https://docs.python.org/3.6/tutorial/modules.html

if __name__ == ‘__main__’:

We see if __name__ == ‘__main__’: quite often. Let’s see what this actually is.

__name__ is global variable in Python that exists in all namespaces. It is attribute of module. It is basically the name of the module as str (string) type.

Show Me Code:

Create a file named ‘mymath.py’ and type the following code and save it. We have defined a simple mathematical square method here.

screenshot-from-2016-09-30-12-51-33

Now create another file named ‘result.py’ in the same directory and type the following code and save it.

screenshot-from-2016-09-30-12-57-10

Now on terminal run the program with ‘python3 result.py’
fotoflexer_photo

Here we have defined a method in a module and using it in another file.

Now let’s look into if __name__ == ‘__main__’:

Open the ‘mymath.py’ file and edit it as given in following:

screenshot-from-2016-09-30-13-56-50

Leave ‘result.py’ unchanged.

Now on your terminal run ‘result.py’. 

fotoflexer_photo1

Here we have imported the module mymath. The variable __name__ is set to the name of the module that is imported.

Now on terminal run ‘mymath.py’

fotoflexer_photo3

We have run the file mymath.py as program itself. And you can see here the variable __name__ is set to the string “__main__”.
And we have checked if __name__ == “__main__” is True execute the following instructions which means if the file is run as standalone program itself execute the following instructions.

If you do  print(type(__name__)) in the program, you will see it returns ‘str’ (string) type.

Happy Coding!

Fedora Women Day 2016

CnZe3pLUAAAwGrm (1)

Fedora Women Day is celebrated to raise awareness and bring Fedora women contributors together. This is a great time to network with other women in Fedora and talk about their contributions and work in Fedora Project.

The event was held at Netaji Subhash Engineering College (NSEC) in Kolkata, India on 15th July, 2016.

Fedora Women Day was also celebrated in Pune, India and Tirana, Albania. https://fedoraproject.org/wiki/Fedora_Women_Day_2016#Local_Events

The event started at 10:30 AM. Women started coming in and it was pretty nice crowd.

The event started with my talk. It was my first talk so I was really excited.

I talked about Fedora Women Day and the purpose. Then I started talking about the work I do in Fedora Project. Most of the part of my talk was regarding Fedora Infrastructure and Fedora Cloud.

Since my most of the contributions lie in Bodhi(Fedora Infrastructure) and Tunirtests(Fedora Cloud) so I specifically gave some insight on these projects. I explained the architecture of Bodhi and Tunirtests and how one can start contributing those specific projects.

I also shared my story on how I started contributing to Fedora Project.

Here is the slide of my talk: trishnaguha.github.io/trishnagslides-what-i-do-in-fedora-how-can-you-get-involved.html

After few hours of my talk I had to leave early for some urgent work. You will find the full event report here: Event Report.

I received Fedora stickers, F24 workstation DVD and Fedora T-shirt, but not sure I can put the T-shirt on, it seems so large :(.

Jpeg

First Guest Session of DGPLUG Summer Training 2016

Screenshot from 2016-07-06 14-06-08

I never imagined that Kushal Das (Mentor of DGPLUG) would ask me to take the first guest session at DGPLUG summer training 2016. I was one of the participants of DGPLUG summer training 2015.

Few days ago I was asked to take the first guest session at DGPLUG summer training 2016 about my journey in FOSS, Python and DGPLUG. I became super excited after hearing that and also it was the first guest session of DGPLUG summer training 2016. It was really unexpected :). The next day I took the session at 18:30 IST on #dgplug channel on IRC.

I started with little introduction about me and let the participants ask Questions after that. The whole session went really interactive. They asked smart questions despite being newbies :).

The mostly asked Questions were How I started my first upstream contribution, How did I select the project I worked on for the first time, What do I do when I am stuck at an issue, How do I manage time to contribute along with my studies, How FOSS helps in career, Steps to contribute in a better way and all.

I really enjoyed answering all kind of Questions those were asked.

You can join the summer training still now. Join #dgplug channel on IRC and the Mailing list. Fill up the form and ping Kushal Das. Feel free to ask if you have any query on IRC or Mailing list. You get this golden opportunity only once a year, so don’t miss it.

The IRC logs are uploaded here. You will find all the conversations here https://dgplug.org/irclogs/2016/Logs-2016-07-01-15-00-trishna.txt.

It feels amazing to be a part of such a great community :).

You Would Never Know Where The Bug Is

Screenshot from 2016-07-05 13-21-26

If you can’t reproduce the bug you would never know where the bug is!

I realized exactly the same when I have been working on a bug of Bodhi. We were pretty clueless about why the bug has arrived. After working on it for long I now believe that I am able to figure out where the bug is, Though the work is still going on. But we are pretty closer to it now. The current state is https://github.com/fedora-infra/bodhi/issues/855.

If we were not be able to reproduce to the bug we would never know why the bug had arrived and believe me it was not really identifiable this time! So before working on patch for a bug we should always try to reproduce it first.

Why Reproduce Bugs?

If you can’t reproduce the bug you would never know where the bug is. Patch doesn’t work just on guess. You are expected to be failed to create a patch if you fail to reproduce the bug.

If you don’t go through the steps when the bug is arrived it is technically impossible to create a patch. After you know why the bug has arrived it is possible for you to fix it as well. If you can’t reproduce the bug you need to create a patch just guessing the issue and you are not sure whether it is going to work or not! So it is not considered as a good practice.  Make sure you are not wasting your time on creating patch about which you are not sure.

Good Bug Reporting: Generally a good bug report contains all required info like when the bug has arrived, what was expected to happen and what has actually happened.

There are bugs about what we have no idea why they have occurred neither the users nor the developers. But the developers can always figure it out by reproducing the bug i.e, creating the same situation(In non-technical word). We will now see How Can We Reproduce Bugs.

How To Reproduce Bugs?

Unittest!

Unittest is one of the certain ways in order to reproduce bugs. I will show a simple demo.

We will write a simple program to check whether a number is odd or even.

Write the code:

Screenshot from 2016-07-05 20-57-56

Write the test:

Screenshot from 2016-07-05 20-58-08

Test is supposed to fail since 6 is an even number. Now we will see what happens:

Screenshot from 2016-07-05 20-54-52

Now we know why the error has occurred. In order to reproduce bugs we always want our test to fail.

This is just the fundamental of unitesting on reproducing bugs. You will know more when working on real world projects.

We can use Pdb also. Check this to see how you can use it.

For Bodhi I have used unittest and mock testing. Here is the testcase I wrote to reproduce the bug I mentioned above: https://paste.fedoraproject.org/386958.

Why is Testing important?

Why is writing tests for your code as important as writing code for your product?

We write Tests to check/test:

  • If the functionalities of the code you wrote or added are working properly.
  • If the new code you added is not breaking the old existing one.

So it’s better to catch the bugs of your code before it reaches to others 😉 .

I was working on fedora-bodhi for last few days and I chose an issue from there to work on. Though it looked simple enough but it really needed some tricks to solve the bug. The interesting thing is that it was not clearly visible that we have to apply some tricks to solve the issue. And I came to know that I had to apply some tricks after I wrote tests for the code I added.

So the solution for the issue has the following conditions:

  1. When an update of a build in bodhi is ‘pending’ and it requests for ‘testing’ and if that request is revoked, the status of that build should be set to ‘unpushed’.
  2. When an update of a build in bodhi is ‘testing’ and it requests for ‘stable’ and if that request is revoked, the status of that build should be set to ‘testing’.

I pushed a patch for it accordingly and received positive comment from threebean 🙂 . Then threebean and lmacken told me to write test for it, because “Sometimes what we see is not the truth!!” . If you look at the patch it really seemed to work. But when I wrote test for the code I added, the test was failing. As pingou suggested I tried printing some debugging statements to make sure if the test is exercising the code I added. Hence I came to know that the test is not going through the code :|. After struggling for a day I catched that my code was conflicting here which also has action ‘revoke’.

Then I modified my code to solve that conflict and received positive review from pingou 😉 .

Now I strongly feel why writing test is as important as writing code and testing makes you write better code as well 🙂 . The earlier patch was not behaving the way it was expected to behave. I wouldn’t realize that my earlier patch would fall if I didn’t write tests for it and if that patch would be merged the bug would be realized after it reached to masses. So isn’t it a smart practice to catch bug of your code by writing tests before it reaches to masses? 😉

The PR can be found here which is finally merged. Thanks to pingou for continuously reviewing my patches and thanks to threebean and lmacken for encouraging and helping me to write tests 🙂 .

 

Handling Deadlock

This post is all about handling deadlock and what I did to avoid deadlock. This is the first time I have worked on handling deadlock. I have chosen an issue from fedora-bodhi which was about handling deadlock. The error was ”Deadlock found when trying to get lock; try restarting transaction” which is usually common when it comes to database.

Deadlock is an unwanted situation that arises when a process waits for indefinite time for a resource that is held by another process. So there is some way to avoid deadlock or handle deadlock. The transaction involved with the deadlock can either be rolled back or restarted.

try:
    Perform table transaction
    break
except:
    Catch the error
    Try again to perform table transaction

Lmacken guided me with some hints to handle Bugzilla deadlock. Since it was bugzilla server side issue it was not simple for me to reproduce the bug. But it was quite easy to handle bugzilla server-side deadlock. The deadlock was arising when an user was going to add comment to a bug in Bugzilla. So it was definitely a server side issue but could be handled with some little trick in bodhiLmacken told me to catch the fault triggered by the call of adding comment and try again. It was an xmlrpclib.Fault exception. Thus the technique to handle deadlock is the same as declared above. And I was finally done with my patch. Thanks to Lmacken for helping me to solve the bug and understand the technique :).

Hence I learnt how to handle deadlock and my pull request was merged 🙂