Mohd Mohtashim has Published 251 Articles

Multithreaded Priority Queue in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:24:30

793 Views

The Queue module allows you to create a new queue object that can hold a specific number of items. There are following methods to control the Queue −get() − The get() removes and returns an item from the queue.put() − The put adds item to a queue.qsize() − The qsize() returns the ... Read More

Synchronizing Threads in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:21:11

10K+ Views

The threading module provided with Python includes a simple-to-implement locking mechanism that allows you to synchronize threads. A new lock is created by calling the Lock() method, which returns the new lock.The acquire(blocking) method of the new lock object is used to force threads to run synchronously. The optional blocking parameter enables you to control whether ... Read More

The Threading Module in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:18:04

8K+ Views

The newer threading module included with Python 2.4 provides much more powerful, high-level support for threads than the thread module discussed in the previous section.The threading module exposes all the methods of the thread module and provides some additional methods −threading.activeCount() − Returns the number of thread objects that are active.threading.currentThread() − Returns the ... Read More

Sending Attachments as an E-mail using Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:09:56

523 Views

To send an e-mail with mixed content requires to set Content-type header to multipart/mixed. Then, text and attachment sections can be specified within boundaries.A boundary is started with two hyphens followed by a unique number, which cannot appear in the message part of the e-mail. A final boundary denoting the ... Read More

Starting a New Thread in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:08:18

457 Views

To spawn another thread, you need to call following method available in thread module −thread.start_new_thread ( function, args[, kwargs] )This method call enables a fast and efficient way to create new threads in both Linux and Windows.The method call returns immediately and the child thread starts and calls function with the passed ... Read More

Sending an HTML e-mail using Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:05:04

578 Views

When you send a text message using Python, then all the content are treated as simple text. Even if you include HTML tags in a text message, it is displayed as simple text and HTML tags will not be formatted according to HTML syntax. But Python provides option to send ... Read More

Database Handling Errors in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:03:40

3K+ Views

There are many sources of errors. A few examples are a syntax error in an executed SQL statement, a connection failure, or calling the fetch method for an already canceled or finished statement handle.The DB API defines a number of errors that must exist in each database module. The following ... Read More

Disconnecting Database in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:02:53

5K+ Views

To disconnect Database connection, use close() method.db.close()If the connection to a database is closed by the user with the close() method, any outstanding transactions are rolled back by the DB. However, instead of depending on any of DB lower level implementation details, your application would be better off calling commit ... Read More

Commit & RollBack Operation in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:02:15

475 Views

COMMITCommit is the operation, which gives a green signal to database to finalize the changes, and after this operation, no change can be reverted back.Here is a simple example to call commit method.db.commit()ROLLBACKIf you are not satisfied with one or more of the changes and you want to revert back ... Read More

Performing Database Transactions using Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 31-Jan-2020 10:01:40

951 Views

Transactions are a mechanism that ensures data consistency. Transactions have the following four properties −Atomicity − Either a transaction completes or nothing happens at all.Consistency − A transaction must start in a consistent state and leave the system in a consistent state.Isolation − Intermediate results of a transaction are not ... Read More

Advertisements